From owner-freebsd-hackers Wed Apr 7 17:31:35 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from nomis.simon-shapiro.org (nomis.simon-shapiro.org [209.86.126.163]) by hub.freebsd.org (Postfix) with SMTP id B032F158E9 for ; Wed, 7 Apr 1999 17:31:22 -0700 (PDT) (envelope-from shimon@simon-shapiro.org) Received: (qmail 39939 invoked by uid 1000); 8 Apr 1999 00:32:55 -0000 Message-ID: X-Mailer: XFMail 1.3 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Wed, 07 Apr 1999 20:32:55 -0400 (EDT) X-Face: --Q&x/1^%>&*}<-P_Nc`3TWi's/BcC?8]O1b,;r$#7wzaSo-\/:3NE{Wm=?;i8{R'h.gsd8 %Hz|Y~=sSW"`VLLNW/{>Ap1%:OB*:KP|LD>" =)I@7r|wU}a To: freebsd-hackers@freebsd.org Subject: wait4 - Proof I am stupid Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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