O_NOCTTY 禁止取得端控制 效?
小弟在 LINUX 上了程序 , 依照 <unix高境程> 一所 ,
(session leader) 若不指明 O_NOCTTY 打端取得控制端 ;
反之 , 若指明就不取得控制端.
但是程序上指明了依然效是取得控制端 , 因我外了
用子程序果然非法取得控制端 , 打 tty12 ,
示 "no job control in the Shell " , 表示控制端取得失 ,
何 O_NOCTTY 效 ?
代如下:
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main()
{
pid_t pid=fork();
if(pid> 0)
exit(0);
if(pid <0)
printf( "first fork error\n "),exit(1);
if(setsid() <0)
printf( "sedsid() error\n "),exit(1);
umask(022);
close(0);
close(1);
close(2);
int _new=open( "/dev/tty12 ",O_RDWR|O_NOCTTY);
dup2(_new,0); //重新指向 stdin
dup2(_new,1); //重新指向 stdout
dup2(_new,2); //重新指向 stderr
execl( "/bin/bash ", "bash ",(char*)0);
}
[解决办法]
bash会重新取得会话终端的