Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!mcsun!unido!rwthinf!marvin.e17.physik.tu-muenchen.de!berg From: berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) Newsgroups: comp.unix.programmer Subject: Re: possible race condition? Message-ID: <4314@rwthinf.UUCP> Date: 10 May 91 13:57:05 GMT References: <1991May9.144935.20078@ge-dab.GE.COM> Sender: news@rwthinf.UUCP Lines: 25 Richard Coleman writes: > if (fork() != 0) > exit(0); /* parent process exits */ > setpgrp(); /* change process group and lose control tty */ > signal(SIGHUP,SIG_IGN); > if (fork() != 0) > exit(0); /* first child process exits */ > /* second child process continues as daemon */ Why not do it this way, and save a LOT of trouble: signal(SIGHUP,SIG_IGN); if (fork() != 0) exit(0); /* parent process exits */ setpgrp(); /* change process group and lose control tty */ if (fork() != 0) exit(0); /* first child process exits */ /* second child process continues as daemon */ Just my $0.02 -- Sincerely, berg@marvin.e17.physik.tu-muenchen.de Stephen R. van den Berg. "I code it in 5 min, optimize it in 90 min, because it's so well optimized: it runs in only 5 min. Actually, most of the time I optimize programs."