Ask a question about daemon
Posted: Mon Mar 11, 2013 9:59 pm
Look:
I am heard if I don't write the second fork,the process can connect
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?
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?