Re: subprocesses lifecycle



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
.



Relevant Pages

  • Re: What CPU/Memory does a Wait cost?
    ... > script, and then let it for 1 hour in each for loop. ... You use the "sleep" command in a shell to put a process to sleep. ... Your job will also die if the server is rebooted. ...
    (comp.lang.perl.misc)
  • Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
    ... the same task) the specifics of my challenge and the script I am ... script parses a single Palm Desktop-exported vCard file having multiple ... or die "Cannot open '$sourcefilename' $!"; ...
    (comp.lang.perl.misc)
  • Re: finding compile time errors
    ... It looks a *lot* like the Perl DBI module which might be the ... Is there a die in PHP with an error message? ... Of course there's a way to kill a script with dieand an error ...
    (comp.lang.php)
  • Update von JMS zu B5:TLT
    ... Ein neues update-posting von JMS. ... Wer sich für die non-B5 Projekte von ... script, and we've now spoken to several of the original cast members, ... Also erstmal mit den Schauspielern verhandeln, die mitmachen ...
    (de.rec.sf.babylon5.misc)
  • Re: Why does Net::SFTP trigger my die handler when no errors?
    ... Kindly consider, if you please, this trivial sample script ... I have defined a custom "die" handler. ... So it would be my guess that Net::SFTP is dying from inside an eval, ... why are you using a SIG die handler, rather than eval, to do whatever it ...
    (comp.lang.perl.misc)