home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / sgi / 16482 < prev    next >
Encoding:
Text File  |  1992-11-16  |  2.3 KB  |  86 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!sol.ctr.columbia.edu!usc!rpi!batcomputer!ghost.dsi.unimi.it!itnsg1.cineca.it!root
  3. From: root@itnsg1.cineca.it (Valter Cavecchia)
  4. Subject: sproc (a question)
  5. Message-ID: <1992Nov16.161558.18141@itnsg1.cineca.it>
  6. Keywords: sproc, child
  7. Organization: Laboratorio di Fisica Computazionale, INFM. Trento Italia
  8. Date: Mon, 16 Nov 1992 16:15:58 GMT
  9. Lines: 75
  10.  
  11.  
  12. I have the following problem: I use sproc to create a new share group
  13. process. Now I would like that if the child dies the parent receives (and
  14. handles) a SIGCLD signal.
  15. The following program does work fine. BUT, if I subsitute the _exit function
  16. with the exit one the parent dies when the child exits (without any signal...)
  17. Is there someone that may explain to me such a behavior?
  18.  
  19.     Thanks a lot in advance.
  20.     valter
  21.  
  22. ----------------------------------cut here---------------------------------
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <signal.h>
  27. #include <sys/types.h>
  28. #include <sys/prctl.h>
  29. #include <sys/sysmp.h>
  30. #include <sys/wait.h>
  31.  
  32. char * global;
  33.  
  34. void Receiver(char * name) 
  35.   int ppid = getppid();
  36.  
  37.   printf("C - Parent id: %d\n", ppid);
  38.   printf("C - %s - global is: %s\n", name, global);
  39.   fflush(stdout);
  40.   unblockproc(ppid);
  41.   kill(ppid, SIGUSR1);
  42.   global[12] = '!';
  43.   sleep(5);
  44.   printf("C - exiting\n");
  45.   _exit(0);
  46. }
  47.  
  48. void Handler(int sig, int code, struct sigcontext * sc)
  49. {
  50.   printf("P - Got signal %d\n", sig); fflush(stdout);
  51.   switch(sig) {
  52.     case SIGUSR1:
  53.       signal(sig, Handler);
  54.       break;
  55.     case SIGCLD:
  56.       printf("P - Child is dead :-(\n");
  57.       exit(0);
  58.   }
  59. }
  60.  
  61. void main(int argc, char ** argv)
  62. {
  63.   int pid;
  64.   struct sigaction action;
  65.  
  66.   global = (char *) malloc(1024 * sizeof(int));
  67.   strcpy(global, "Hello, World?\n");
  68.  
  69.   printf("Maximum number of processes: %d\n", prctl(PR_MAXPROCS));
  70.   printf("Maximum parallel processes : %d\n", prctl(PR_MAXPPROCS));
  71.   printf("Available processors       : %d\n", sysmp(MP_NAPROCS));
  72.  
  73.   signal(SIGUSR1, Handler);
  74.   signal(SIGCLD, Handler);
  75.  
  76.   prctl(PR_SETEXITSIG, SIGCLD);
  77.  
  78.   pid = sproc(Receiver, PR_SALL|PR_BLOCK, "MDT Share Group Process");
  79.  
  80.   printf("P - Global is: %s\n", global); fflush(stdout);
  81.   for(;;);
  82.  
  83. ----------------------------------cut here---------------------------------} 
  84.   
  85.