jian@kuhub.cc.ukans.edu (09/27/90)
I tried to send a signal (SIGUSR1) from a child process to its parent process by using kill() system call in C. The result was funny. Whenever the parent process received the signal, it died immediately. I don't know what goes wrong in my program. Any help appreciated. Jian Q. Li jian@kuhub.cc.ukans.edu ---------------------------------------------------------------------------- Following is my sample program: void parent_process() { int ppid; .... switch( pid = fork()) { case -1: perror("for()"); exit(1); case 0: ppid = getpid(); child_process(ppid); default: signal(SIGUSR1, catch_usr1); } ..... } void catch_usr1() { printf("Catch the SIGUSR1 signal\n"); usr_break = 1; } void child_process(parent_id) int parent_id; { .... kill(parent_id, SIGUSR1); .... }
gt0178a@prism.gatech.EDU (BURNS,JIM) (09/27/90)
in article <25784.2700d355@kuhub.cc.ukans.edu>, jian@kuhub.cc.ukans.edu says: > switch( pid = fork()) { > case -1: > perror("for()"); > exit(1); > case 0: > ppid = getpid(); Try getppid(). > child_process(ppid); > > default: > signal(SIGUSR1, catch_usr1); Might want to add: wait(0); sleep(5); -- BURNS,JIM Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332 uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a Internet: gt0178a@prism.gatech.edu
cpcahil@virtech.uucp (Conor P. Cahill) (09/27/90)
In article <25784.2700d355@kuhub.cc.ukans.edu> jian@kuhub.cc.ukans.edu writes: > >I tried to send a signal (SIGUSR1) from a child process to its parent process >by using kill() system call in C. The result was funny. Whenever the parent >process received the signal, it died immediately. I don't know what goes wrong >in my program. Any help appreciated. > >void parent_process() >{ > int ppid; > switch( pid = fork()) { > case -1: perror("for()"); exit(1); > case 0: ppid = getpid(); child_process(ppid); > default: signal(SIGUSR1, catch_usr1); > } I assume the getpid() is a typo and you really had getppid() in the code. Most likely the child process is executing the kill() before the parent process has a chance to execute the signal(). Try running the signal before the fork (and if necessary, reset it in the child). -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170
dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (09/29/90)
In article <25784.2700d355@kuhub.cc.ukans.edu> jian@kuhub.cc.ukans.edu writes: > >I tried to send a signal (SIGUSR1) from a child process to its parent process >by using kill() system call in C. The result was funny. Whenever the parent >process received the signal, it died immediately. I don't know what goes wrong >in my program. Any help appreciated. > >void parent_process() >{ > int ppid; > .... > > switch( pid = fork()) { ...... > > default: > signal(SIGUSR1, catch_usr1); > } > The child can post the signal to the parent before the parent returns from the fork, if this happens the default action (termination) will occur. Set up the signal handler before the fork. -- Dave Eisen Home: (415) 323-9757 dkeisen@Gang-of-Four.Stanford.EDU Office: (415) 967-5644 1447 N. Shoreline Blvd. Mountain View, CA 94043