home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / aix / 8913 < prev    next >
Encoding:
Text File  |  1992-08-19  |  1.7 KB  |  75 lines

  1. Path: sparky!uunet!ukma!darwin.sura.net!mips!decwrl!bu.edu!cs!tasos
  2. From: tasos@cs.bu.edu (Anastasios Kotsikonas)
  3. Newsgroups: comp.unix.aix
  4. Subject: system() and SIGCHLD
  5. Message-ID: <94029@bu.edu>
  6. Date: 19 Aug 92 14:13:42 GMT
  7. Sender: news@bu.edu
  8. Organization: Computer Science Department, Boston University, Boston, MA, USA
  9. Lines: 63
  10. Originator: tasos@cs
  11.  
  12. A few weeks ago I posted the following question to comp.unix.programmer:
  13.  
  14. If process A forks B, then A does a system(), is A supposed to receive
  15. a SIGCLD when system() returns?
  16.  
  17. All replies said no, and some people were astonished that AIX had this
  18. "problem" [really!]. Well, this time I have included the program below
  19. to show that it does indeed happen, on a number of hosts actually.
  20.  
  21. If any can suggest a workaround I would really appreciate it.
  22.  
  23. Tasos
  24.  
  25. ------------------------------  systest.c  ----------------------------
  26. #include <stdio.h>
  27. #include <signal.h>
  28.  
  29. int pid;
  30.  
  31. main ()
  32. {
  33.   extern int sighandle();
  34.  
  35. #ifdef SIGCLD
  36.   signal (SIGCLD, (void *) sighandle);
  37. #else
  38.   signal (SIGCHLD, (void *) sighandle);
  39. #endif
  40.   if ((pid = fork ()) < 0)
  41.     perror ("Cannot fork"),
  42.     exit (1);
  43.   else if (pid == 0)
  44.     while (1);
  45.   else
  46.     system ("/bin/echo > /dev/null");
  47.   sleep (2);
  48.   printf ("system() OK.\n");
  49. #ifdef SIGCLD
  50.   signal (SIGCLD, SIG_DFL);
  51. #else
  52.   signal (SIGCHLD, SIG_DFL);
  53. #endif
  54.   kill (pid, SIGKILL);
  55.   exit (0);
  56. }
  57.  
  58. sighandle (sig)
  59. int sig;
  60. {
  61.   fprintf (stderr, "system() bug.\n");
  62. #ifdef SIGCLD
  63.   signal (SIGCLD, SIG_DFL);
  64. #else
  65.   signal (SIGCHLD, SIG_DFL);
  66. #endif
  67.   kill (pid, SIGKILL);
  68.   exit (2);
  69. }
  70. -- 
  71. --
  72. Tasos Kotsikonas |   tasos@cs.bu.edu    | Work : Advanced Visual Systems
  73. Ex BU Country     |                      | email: tasos@avs.com
  74. Club Member.     |                      | Duties: none
  75.