From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96075319906658.tru64-unix-managers.marc@archive.invalid> From: "Ian Nicholls" Date: Tue, 23 May 1995 06:35:26 +0000 To: tru64-unix-managers Subject: SUMMARY so far: Defunct daemon problem X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96075319906658 The problem briefly: The following (omitted) 'C' program creates a daemon process which in turn forks off another child process. The problem we are experiencing is that under OSF/1 version 3.22 Unix when the last child exits, its process remains as a . This problem does not occur under AT&T SVR4 Unix. So far, the replies have told me that I should use the wait3() routine to wait for the status of the child. I have chosen one, the briefest and quite clear, to include below. We set up the signal handler so we don't have to wait for the SIGCLD until we get one. Then it's a quick routine to accept the signal and the spawning program can get back to work. ================== From: joe@resptk.bhp.com.au I experienced a similar problem on SUN's where a lot of defunct processes were left hanging after reforking another process. I dont know whether this will work on OSF/1 but instead of ignoring the SIGCLD signal you should trap it and use a 'wait3' command so that it dies off nicely. That is the parent process doing the forking sets up to trap the SIGCLD signal from the child process. The parent waits until the child dies off. If the parent does not wait and continues the child has no reference to its parent and thus becomes defunct. Thats what I understand about 'defunct' processes from memory, I could not find any references on the subject. The following is the code I used to get around the same problem: --------------------------------------------------------------------------- /* * Now fork a process & execute a program */ signal(SIGCLD, sig_child); /* trap child's exit */ if ((pid_child = fork()) == 0) { /* child */ execl(.........); exit(0); } ------------------------- /* * Use WNOHANG in wait3 to stop defuncts */ int sig_child() { int pid; union wait status; while ((pid = wait3(&status, WNOHANG, (struct rusage *) 0)) > 0); return; } ------------------------------------------------------------------------------- Thanks also to those others who replied: alan@nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward inodes) Ray Bellis "Reinhard Doelz, Biocomputing Basel" Ilja Hallberg -- << E-mail: inicholl@coles.com.au Phone: +61 3 9829 6088, Fax: +61 3 9829 6886 >> << Post: Coles Supermarkets, PO Box 480, Glen Iris 3146, Australia >>