possible race condition?

Stephen R. van den Berg berg at marvin.e17.physik.tu-muenchen.de
Fri May 10 23:57:05 AEST 1991


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 at 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."



More information about the Comp.unix.programmer mailing list