home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / programm / 4566 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.3 KB

  1. Path: sparky!uunet!cs.utexas.edu!ut-emx!ibmchs!auschs!awdprime.austin.ibm.com!ravikm
  2. From: ravikm@austin.ibm.com (Ravi K Mandava)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: calling system() with SIGCLD ignored (SysV).
  5. Message-ID: <1992Sep4.160419.2012@awdprime.austin.ibm.com>
  6. Date: 4 Sep 92 16:04:19 GMT
  7. References: <1992Sep2.164144.11558@glas.rtsg.mot.com>
  8. Sender: news@awdprime.austin.ibm.com (USENET News)
  9. Reply-To: piobe!ravikm@ibmpa.awdpa.ibm.com
  10. Distribution: comp
  11. Organization: IBM Austin
  12. Lines: 56
  13. Originator: ravikm@piobe.austin.ibm.com
  14.  
  15.  
  16. In article <1992Sep2.164144.11558@glas.rtsg.mot.com>, hartnett@glas.rtsg.mot.com (Ger Hartnett) writes:
  17. > I need to spawn off processes and not allow them to become zombie when
  18. > finished. I also need to make calls to the system() function in the
  19. > parent process.
  20.  
  21.     You could block SIGCHLD signals before you call system() function.
  22.     However, since system() does its own waitpid(), you'd need to
  23.     reset your signal handler (from SIG_IGN or a user-defined function
  24.     with wait()) to SIG_DFL, so that its waitpid() would receive its
  25.     child's exit status correctly.
  26.  
  27.     An example piece of code could be:
  28.  
  29.         ...
  30.         #include <sys/types.h>
  31.         #include <signal.h>
  32.  
  33.         ...
  34.         struct sigaction    newchldact, oldchldact;
  35.         sigset_t        newmask, oldmask;
  36.         ...
  37.         (void) sigemptyset(&newmask);
  38.         (void) sigaddset(&newmask, SIGCHLD);
  39.         if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) == -1)
  40.            ...
  41.  
  42.         newchldact.sa_handler = SIG_DFL;
  43.         (void) sigemptyset(&newchldact.sa_mask);
  44.         newchldact.sa_flags = 0;
  45.         if (sigaction(SIGCHLD, &newchldact, &oldchldact) == -1)
  46.            ...
  47.  
  48.         ... = system("...");
  49.         ...    /* return code checking */
  50.  
  51.         if (sigaction(SIGCHLD, &oldchldact, (struct sigaction *)NULL)
  52.             == -1)
  53.            ...
  54.  
  55.         if (sigprocmask(SIG_SETMASK, &oldmask, (sigset_t *)NULL) == -1)
  56.            ...
  57.  
  58.  
  59.     Or, alternatively, you could still keep your original signal handler
  60.     (SIG_IGN or a user-defined function with wait()) installed, but
  61.     avoid using system().  That is, replace system() call with your
  62.     own code calling fork() and exec() without a wait() (if you're not
  63.     interested in the child's exit status).
  64.  
  65. Hope this helps,
  66. -- 
  67. *******************************************************************************
  68. Ravi K Mandava        email:    piobe!ravikm@ibmpa.awdpa.ibm.com
  69. *******************************************************************************
  70.