Home > Archive > PERL Beginners > March 2005 > When does a process become defunct
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
When does a process become defunct
|
|
| Ramprasad A Padmanabhan 2005-03-28, 8:55 am |
| Hi all,
I am writing a daemon in perl , where the parent just forks on some
requests and the children take over. But I found many child processes
becoming defunct. I am not sure why. I am catching SIG_CHLD alright.
To reproduce the problem I have just written a skeleton of my script.
The parent process just forks 20 child processes which just sleep and
exit after some random seconds. When I run this too I find some defunct
processes, the problem is I do not get defunct processes everytime. So
this behaviour is not reproducible ( at least with my script :-) )
I am using perl 5.83 on linux ( fedora-3)
Can someone help me out avoiding these zombies
Thanks
Ram
------------------------------------ MY SCRIPT HERE ---------
use strict;
$GLOBAL::NUM_CH =0;
$|=1;
$SIG{CHLD}=\&count_ch;
foreach(1..20){
unless(fork()){
sleep int(rand(20));
exit 0;
}
print "No of children running now " . ++$GLOBAL::NUM_CH . "\n";
sleep 2;
}
foreach (1..100){
print "PARENT CHECK LOOP: No of children running now " .
$GLOBAL::NUM_CH . "\n";
exit(0) unless($GLOBAL::NUM_CH);
sleep 5;
}
print "Oops : Something went wrong Not all children have quit\n";
sub count_ch {
print "1 CHILD QUIT: No of children running now " . --$GLOBAL::NUM_CH
.. "\n";
wait();
}
--------------------------------- END OF SCRIPT --------
----------------------------------------------------------
Netcore Solutions Pvt. Ltd.
Website: http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
----------------------------------------------------------
| |
| Steven Schubiger 2005-03-28, 8:55 am |
| On 28 Mar, Rampra A Padmanabhan wrote:
> I am writing a daemon in perl , where the parent just forks on some
> requests and the children take over. But I found many child processes
> becoming defunct.
> wait();
perldoc -f waitpid
--
The trouble with having an open mind, of course,
is that people will insist on coming along and trying to put things in it.
-- Terry Pratchett
| |
|
|
| Ramprasad A Padmanabhan 2005-03-28, 8:55 am |
| On Mon, 2005-03-28 at 14:35, Steven Schubiger wrote:
> On 28 Mar, Rampra A Padmanabhan wrote:
>
>
>
> perldoc -f waitpid
I was not very clear on usefulness of waitpid()
>From what I understand , I will have to do a waitpid for every fork I
do.
Can you show me how I could use waitpid() in my script ( non blocking )
Thanks
Ram
----------------------------------------------------------
Netcore Solutions Pvt. Ltd.
Website: http://www.netcore.co.in
Spamtraps: http://cleanmail.netcore.co.in/directory.html
----------------------------------------------------------
|
|
|
|
|