Path: utzoo!attcan!uunet!husc6!uwvax!oddjob!gargoyle!att!chinet!mcdchg!usenet From: lenb@houxs.UUCP (Len Brown) Newsgroups: comp.unix Subject: Re: Children's exit() status Keywords: summary of responses Message-ID: <7967@mcdchg.UUCP> Date: 20 May 88 15:44:35 GMT References: <4626@mcdchg.UUCP> Sender: usenet@mcdchg.UUCP Lines: 24 Approved: usenet@mcdchg.UUCP Thanks for the numerous replies, here's a summary: "What is the proper way for a parent process to wait for multiple child processes to exit?" People have warned me that when many children exit simultaneously, the parent executing wait(2) loop may miss the return status of some of them. The truth is that the parent will never miss child exit status if the loop is constructed properly. When a child exits, UNIX queues it as a zombie until its parent does a wait(2). If the parent exits, init will inherit the children and wait(2) for them. A simple wait(2) loop would suffice, except sometimes wait(2) returns when you don't expect it to. The frequently cited example is when the parent process is in a pipeline. The sh(1) may make other pipeline members children of the parent. When they exit, they wake up the parent. So all one has to do is keep a list of the known children's pid's. When wait(2) returns, check the list to be sure it is a known child that woke you up. Len Brown, AT&T Data Systems Group, Holmdel, NJ. {ihnp4 etc}!houxs!lenb