Date: Wed, 07 Apr 1999 20:32:55 -0400 (EDT) From: Simon Shapiro <shimon@simon-shapiro.org> To: freebsd-hackers@freebsd.org Subject: wait4 - Proof I am stupid Message-ID: <XFMail.990407203255.shimon@simon-shapiro.org>
next in thread | raw e-mail | index | archive | help
Hi Y'll, Please bear with me: int x; pid_t my_pgid; switch (fork()) { case 0: (void)setpgid(getpid(), getpid()); my_pgid = getpgrp(); for (x = 0; x < 10; x++) { switch (fork()) { case 0: /* Go do something useful */ break; case -1: /* Ooops! */ break; default: /* Ignore */ break; } } exit(0); break;; case -1: /* Ooops! */ break; default: /* ignore */ break; } /* * So far, this code should (and does) fork a process. * This process (child then changes its process group to something else * than the parent and then forks 10 children. * * Now the parent wants to wait for the grandchidren... */ x = 10; /* redundant, for demo purposes... */ while (x) { pid_t y; int z; switch (y = wait4((-1)* my_pgid, &z, NULL)) { case 0: /* Never happens */ break; case -1: /* ALWAYS HAPPENS */ break; default: /* Never happens */ break; } } Question: Why? Obviously I am doing something wrong, but what? I tried changing just about any argument to the wait4() function. Eliminating the child and having the grandparent fork and wait for the chilfren via ``wait(0);'' works. The chilfren are there and all seems correct; the children are in a new process group (different than grandpa's), once the son exits, they all have ppid of 1, etc. Any suggestion will be greatly appreciated. Note: The ``code'' above is illutration only... Sincerely Yours, Shimon@Simon-Shapiro.ORG 770.265.7340 Simon Shapiro Unwritten code has no bugs and executes at twice the speed of mouth To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.990407203255.shimon>