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
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 08:22 PM
about child process compbug UNIX for Dummies Questions & Answers 12 03-22-2006 03:55 PM
Catching signal and piping joseph_ng High Level Programming 7 11-14-2005 07:04 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 01:41 PM
Child Process PID skannan High Level Programming 2 06-10-2002 04:54 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2008
Registered User
 

Join Date: Feb 2007
Posts: 7
Stumble this Post!
catching a signal from child process

i am creating children processes using fork system call
every child i create goes to sleep for random time.
when child stops running how can i catch his signal and turminate the child
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-02-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 239
Stumble this Post!
Code:
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>

void childexit(int signal_num) {
int retval, nval;
char buf[256];
                 bzero(buf,256);
                 nval =   waitpid(0,&retval,WNOHANG);  
                 sprintf(buf,"Waited on child %d which exited with code = %d\n",nval,retval);       
                  write(STDOUT_FILENO,buf,256);
}

int main(void) {

                    signal(SIGCHLD,childexit);
                    /*rest of code*/
}
Reply With Quote
  #3 (permalink)  
Old 05-03-2008
Registered User
 

Join Date: Feb 2007
Posts: 7
Stumble this Post!
ok i think i got it
thanks
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:35 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