Code: Select all
int main()
{
if(fork())
exit(0);
setsid();
//the second fork
if(fork())
exit(0);
//=========
int fd=open("/dev/tty",O_RDWR);
ioctl(fd, TIOCSCTTY, 1);
while(1)
{
sleep(20);
write(fd,"hello",10);
}
//daemon code
}
a control terminal,but I find I write the second fork or don't write
the codes,the screen couldn't display the string "hello",Why?
How to correct my codes?