O_NOCTTY 禁止取得終端控制 無效? 系統不讓我給分...

superstition 2007-01-03 10:08:22
小弟在 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);

}

感激不盡希望各位大俠解惑~~~~ 謝謝
...全文
77 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,110

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧