home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!ut-emx!ibmchs!auschs!awdprime.austin.ibm.com!ravikm
- From: ravikm@austin.ibm.com (Ravi K Mandava)
- Newsgroups: comp.unix.programmer
- Subject: Re: calling system() with SIGCLD ignored (SysV).
- Message-ID: <1992Sep4.160419.2012@awdprime.austin.ibm.com>
- Date: 4 Sep 92 16:04:19 GMT
- References: <1992Sep2.164144.11558@glas.rtsg.mot.com>
- Sender: news@awdprime.austin.ibm.com (USENET News)
- Reply-To: piobe!ravikm@ibmpa.awdpa.ibm.com
- Distribution: comp
- Organization: IBM Austin
- Lines: 56
- Originator: ravikm@piobe.austin.ibm.com
-
-
- In article <1992Sep2.164144.11558@glas.rtsg.mot.com>, hartnett@glas.rtsg.mot.com (Ger Hartnett) writes:
- >
- > I need to spawn off processes and not allow them to become zombie when
- > finished. I also need to make calls to the system() function in the
- > parent process.
-
- You could block SIGCHLD signals before you call system() function.
- However, since system() does its own waitpid(), you'd need to
- reset your signal handler (from SIG_IGN or a user-defined function
- with wait()) to SIG_DFL, so that its waitpid() would receive its
- child's exit status correctly.
-
- An example piece of code could be:
-
- ...
- #include <sys/types.h>
- #include <signal.h>
-
- ...
- struct sigaction newchldact, oldchldact;
- sigset_t newmask, oldmask;
- ...
- (void) sigemptyset(&newmask);
- (void) sigaddset(&newmask, SIGCHLD);
- if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) == -1)
- ...
-
- newchldact.sa_handler = SIG_DFL;
- (void) sigemptyset(&newchldact.sa_mask);
- newchldact.sa_flags = 0;
- if (sigaction(SIGCHLD, &newchldact, &oldchldact) == -1)
- ...
-
- ... = system("...");
- ... /* return code checking */
-
- if (sigaction(SIGCHLD, &oldchldact, (struct sigaction *)NULL)
- == -1)
- ...
-
- if (sigprocmask(SIG_SETMASK, &oldmask, (sigset_t *)NULL) == -1)
- ...
-
-
- Or, alternatively, you could still keep your original signal handler
- (SIG_IGN or a user-defined function with wait()) installed, but
- avoid using system(). That is, replace system() call with your
- own code calling fork() and exec() without a wait() (if you're not
- interested in the child's exit status).
-
- Hope this helps,
- --
- *******************************************************************************
- Ravi K Mandava email: piobe!ravikm@ibmpa.awdpa.ibm.com
- *******************************************************************************
-