killing the children

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys,

i'm having a bit of a problem here with the exec functionality. I seem
to be unable to kill the children of my process. Hope you can help me
with this one.

I'm doing a client-server setup where the server requests the clients
to start instances of a certain application and now the bugger doesn't
seem to die properly. The code in nutshell is here, i'll eliminate my
crappy message handling and just quote the handler funcs:

<start block>
$pid = fork;
if ( $pid == 0 )
  exec( $my_command,$my_args) or die "can't do it Jim!";
} else {
$jobs = $my_args;
</start block>

<kill block>
foreach ( keys( $jobs ) )
  kill 9,$_;
delete %jobs;
</kill block>

What happens is that the exec starts the program properly and returns
a pid. the kill however seems to be unable
to do anything to the program that is executed, it just keeps

Am i actually execing a command shell instance that then starts the
program as child and my kill hangs there?

At the moment coding in Win32 environment but the code should port to
linux/osX as well.


Re: killing the children

Quoted text here. Click to load it

You should include enough of the other stuff to make it actually runnable.

my $my_command="perl";
my @my_args=('-le', 'warn $$; sleep 2; warn $$');
$pid = fork;
if ( $pid == 0 )
  exec( $my_command,@my_args) or die "can't do it Jim!";
} else {
$jobs = $my_args[0];
sleep 1;
foreach ( keys( %jobs ) )
  warn "killing $_";
  kill 9,$_;
sleep 3;

On Linux, the second warn $$ never gets executed because that child has
already been killed.  On Windows, sometimes it works that way and sometimes
it doesn't. An example of one of the times it doesn't:

2364 at -e line 1.
killing -3872 at line 16.
2364 at -e line 1.

Quoted text here. Click to load it

You shouldn't be, since you are using the list form of exec.  On Windows,
lords knows what might be going on.

Quoted text here. Click to load it

Good luck with that.


-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Site Timeline