Re: subprocesses lifecycle
- From: Matthieu Imbert <breafk@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Aug 2008 10:06:31 +0200
Eric Pozharski wrote:
perl -mIO::Pipe -wle '
$pipe = IO::Pipe->new;
if(fork) {
$pipe->reader;
sleep 1;
die; };
$pipe->writer;
open $h, q|</etc/passwd|;
while($l = <$h>) {
print $pipe $l;
sleep 1; }
' ; ps -O ppid t ; sleep 40 ; ps -O ppid t
Died at -e line 6.
PID PPID S TTY TIME COMMAND
12782 1 S pts/1 00:00:00 perl -mIO::Pipe -wle ?$pipe = IO::Pipe->new;
12783 29996 R pts/1 00:00:00 ps -O ppid t
29996 29991 S pts/1 00:00:11 bash
PID PPID S TTY TIME COMMAND
12785 29996 R pts/1 00:00:00 ps -O ppid t
29996 29991 S pts/1 00:00:11 bash
See that? There's no problem with dieing (I won't comment why the
system needs more that half a minute to get rid off child (kernel?
shell? init? panic...); YMMV).
However you say that you have a problem. I suppose you have to
investigate why your script attempts to collect zombies. It should not
unless told so.
Is there a way to force the end of all subprocesses when calling die?
Second. No one can kill process which hangs in syscall till the process
gets out into userspace. So you'd be better finding why you collect.
Hi Eric, here is how i understand things:
In your example code, the child process stays alive after the end of
parent process. As there are probably 30 to 40 lines in /etc/passwd and
it sleeps 1 second for each line, it's not surprising that it takes
about half a minute to end and die.
This confirms the fact that perl does not kill subprocesses when calling
die.
But it does not explain why in your example the parent script returns
immediately when calling die, while in my case the parent script waits
for children to end before returning. I thought that this could be
related to the way you create child processes (with fork), whereas i
create then with open. But this little test script returns immediately:
perl -e '
open (CHILD,"sleep 30 |");
die "byebye";
'
So the problem must come from something else. i have to understand why
it behaves differently in my first script (i'll try to isolate the
simplest reproducible demonstration code of the problem).
Currently, as a workaround, i added code that finds all subprocesses of
my script and sends TERM, then wait 10s, then send KILL to all of them
Matthieu
.
- Follow-Ups:
- Re: subprocesses lifecycle
- From: Hans Mulder
- Re: subprocesses lifecycle
- References:
- subprocesses lifecycle
- From: Matthieu Imbert
- Re: subprocesses lifecycle
- From: Eric Pozharski
- subprocesses lifecycle
- Prev by Date: FAQ 7.23 How do I create a switch or case statement?
- Next by Date: perl threads
- Previous by thread: Re: subprocesses lifecycle
- Next by thread: Re: subprocesses lifecycle
- Index(es):
Relevant Pages
|