- 论坛徽章:
- 0
|
我用setsid后,然后去读写前面打开的控制终端,apue里面讲后台进程读控制终端会产生SIGTTIN信号,但是我这下面sig_ttin函数一直没有执行,后来我把read换成write发现也没有产生SIGTTOU信号,不明白。谁能详细讲讲控制终端。
#include<fcntl.h>
#include<stdio.h>
#include<unistd.h>
#include<signal.h>
#include<stdlib.h>
static void sig_ttin(int no)
{
printf("sig_ttin\n");
}
int main()
{
pid_t pid;
if ((pid = fork()) < 0){
perror("fork");
exit(1);
} else if (0 == pid) {// child
int result = open("/dev/pts/0", O_RDWR);
if (result != -1)
printf("open success!\n");
setsid();
printf("pid:%d, ppid:%d, gpid:%d, sid:%d\n", getpid(), getppid(), getpgrp(), getsid(0));
signal(SIGTTIN, sig_ttin);
char c;
if (read(result, &c, 1) < 0)
perror("read");
close(result);
result = open("/dev/pts/0", O_RDWR);
if (result < 0)
printf("can't open tty\n");
}
exit(0);
}
|
|