home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- 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
- From: root@itnsg1.cineca.it (Valter Cavecchia)
- Subject: sproc (a question)
- Message-ID: <1992Nov16.161558.18141@itnsg1.cineca.it>
- Keywords: sproc, child
- Organization: Laboratorio di Fisica Computazionale, INFM. Trento Italia
- Date: Mon, 16 Nov 1992 16:15:58 GMT
- Lines: 75
-
-
- I have the following problem: I use sproc to create a new share group
- process. Now I would like that if the child dies the parent receives (and
- handles) a SIGCLD signal.
- The following program does work fine. BUT, if I subsitute the _exit function
- with the exit one the parent dies when the child exits (without any signal...)
- Is there someone that may explain to me such a behavior?
-
- Thanks a lot in advance.
- valter
-
- ----------------------------------cut here---------------------------------
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <signal.h>
- #include <sys/types.h>
- #include <sys/prctl.h>
- #include <sys/sysmp.h>
- #include <sys/wait.h>
-
- char * global;
-
- void Receiver(char * name)
- {
- int ppid = getppid();
-
- printf("C - Parent id: %d\n", ppid);
- printf("C - %s - global is: %s\n", name, global);
- fflush(stdout);
- unblockproc(ppid);
- kill(ppid, SIGUSR1);
- global[12] = '!';
- sleep(5);
- printf("C - exiting\n");
- _exit(0);
- }
-
- void Handler(int sig, int code, struct sigcontext * sc)
- {
- printf("P - Got signal %d\n", sig); fflush(stdout);
- switch(sig) {
- case SIGUSR1:
- signal(sig, Handler);
- break;
- case SIGCLD:
- printf("P - Child is dead :-(\n");
- exit(0);
- }
- }
-
- void main(int argc, char ** argv)
- {
- int pid;
- struct sigaction action;
-
- global = (char *) malloc(1024 * sizeof(int));
- strcpy(global, "Hello, World?\n");
-
- printf("Maximum number of processes: %d\n", prctl(PR_MAXPROCS));
- printf("Maximum parallel processes : %d\n", prctl(PR_MAXPPROCS));
- printf("Available processors : %d\n", sysmp(MP_NAPROCS));
-
- signal(SIGUSR1, Handler);
- signal(SIGCLD, Handler);
-
- prctl(PR_SETEXITSIG, SIGCLD);
-
- pid = sproc(Receiver, PR_SALL|PR_BLOCK, "MDT Share Group Process");
-
- printf("P - Global is: %s\n", global); fflush(stdout);
- for(;;);
-
- ----------------------------------cut here---------------------------------}
-
-