The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
signal handling question fox_hound_33 High Level Programming 7 05-31-2008 10:53 AM
Signal handling in Perl obelix Shell Programming and Scripting 6 12-19-2007 08:08 PM
signal handling in shell script Raom UNIX for Advanced & Expert Users 4 12-08-2005 02:55 AM
Handling SIGUSR2 signal diganta UNIX for Advanced & Expert Users 3 11-21-2005 07:18 AM
Sun Sol 5.1 Signal Values Texan_BOB SUN Solaris 3 09-11-2003 01:55 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-12-2006
Registered User
 

Join Date: Jun 2006
Posts: 6
Stumble this Post!
Signal Handling

Hi folks
I'm trying to write a signal handler (in c on HPUX) that will catch the child process launched by execl when it's finished so that I can check a compliance file.
The signal handler appears to catch the child process terminating however when the signal handler completes the parent process crashes and restarts.

Please can anyone give me any advice as to what I'm doing wrong.

// main
signal(SIGCHLD, TerminateChild);

int pid = fork();
// if pid O.K
execl(params); // launch a seperate Java process

// end main

void TerminateChild(int sig)
{
int pid, status;
pid = waitpid(-1, &status, WNOHANG);

// Check a file for a compliance
// send IPC message
signal(SIGCHLD, TerminateChild);
}
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-12-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,794
Stumble this Post!
Is there a reason you cannot call waitpid() -- or wait()?

Signals arrive asynchronously, so you parent process' code could be in any state when the signal arrives..... but if you do stuff, then call wait() you're at a known point.
Reply With Quote
  #3 (permalink)  
Old 07-12-2006
Registered User
 

Join Date: Jun 2006
Posts: 6
Stumble this Post!
Hi
I have used the following call to waitpid in my TerminateChild handler:
pid = waitpid(-1, &status, WNOHANG);

Have I used it incorrectly?
Reply With Quote
  #4 (permalink)  
Old 07-12-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,323
Stumble this Post!
I don't think that jim means that you are using waitpid incorrectly. What he means is that your program might be at *any* stage when SIGCHLD is received. But instead, if you carry out some execution, and then wait at a particular point in the code, you know what point you have stopped and 'waitpid'ed for the child.

And about that waitpid, is it necessary to specify WNOHANG? I mean you have received SIGCHLD, so the child process's info is available anyway...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0