LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-19-2006, 06:35 AM   #1
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Rep: Reputation: 30
how to get a list of child processes?


hiho@ll

how do i obtain a list of child processes, which is very actual?
the problem i have: i need some statistics of my childs
this statistics are shared through shared memory
the problem: if a child dies, i don't know how "actual" my statistic is

i thought about using signals
but which signals should be caught by a child to know that it will die?
is segfault the only one?
or is it possible to receive a signal from a child by the parent so the parent knows child with pid pid dies?

thx@ll
 
Old 01-19-2006, 08:37 AM   #2
Thinking
Member
 
Registered: Oct 2003
Posts: 249

Original Poster
Rep: Reputation: 30
ok i think i found it:

if a child dies it sends SIGCHILD signal to the parent

parent:
Code:
signal(SIGCHILD,mysigchildfunc);

static void mysigchildfunc(){
 int status=0;
 pid_t pid = waitpid(-1,&status,WNOHANG);
 if(pid>0){
  // do some stuff so parent knows a child died (e.g. cleanup of shared memory,....)
 }
}
 
Old 01-19-2006, 08:42 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You want the SIGCHLD. This signal is sent whenever a child process stops. This is to allow the parent to do any necessary processing. If you don't handle it then you will end up getting zombie processes. Typically it is processed in a waitpid() For an example on how to code this got to:

Advanced Unix Programming Examples


graeme.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forking 7 child processes ianomc Programming 5 11-07-2004 01:33 PM
Limiting child processes in Apache? Phaethar Linux - Software 2 11-02-2004 06:24 PM
Rotatelogs - Do I have too many child processes? fireman949 Linux - Software 2 06-08-2004 03:04 PM
parent and child processes skora Programming 5 11-02-2003 11:41 AM
Memory usage when spawning child processes brianvdc Programming 4 10-24-2003 07:03 AM


All times are GMT -5. The time now is 10:21 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration