Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > killing the children

Reply
Thread Tools

killing the children

 
 
lekonna
Guest
Posts: n/a
 
      03-02-2008
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{$pid} = $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
running.

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.

Br,
Lekonna
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      03-02-2008
lekonna <(E-Mail Removed)> wrote:
>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.
>
>Am i actually execing a command shell instance that then starts the
>program as child and my kill hangs there?


Well, there's your problem. Your kill() is killing the shell (which at that
time is probably dead already anyway) but not the children of the shell.

You need a way to identify/kill the grandchildren of the perl process,
maybe by killing the process tree of the shell or have the shell return the
ID of it's own children or something like that.

jue
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-02-2008
lekonna <(E-Mail Removed)> wrote:
> 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:


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{$pid} = $my_args[0];
}
sleep 1;
foreach ( keys( %jobs ) )
{
warn "killing $_";
kill 9,$_;
}
sleep 3;
__END__

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:

H:\perl_misc>perl kill.pl
2364 at -e line 1.
killing -3872 at kill.pl line 16.
2364 at -e line 1.



> 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
> running.
>
> Am i actually execing a command shell instance that then starts the
> program as child and my kill hangs there?


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

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


Good luck with that.

Xho

--
-------------------- 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.
 
Reply With Quote
 
C. Lumina
Guest
Posts: n/a
 
      03-03-2008
lekonna wrote:
> 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 must say, perhaps you could of chosen a better wording for the subject
line!

Best way I take care of situations like this is to maintain a list of
any children created by the parent and make sure they get raped properly
on exit.

-CL


 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      03-03-2008
"C. Lumina" <(E-Mail Removed)> wrote:
> lekonna wrote:
> > 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 must say, perhaps you could of chosen a better wording for the subject
> line!
>
> Best way I take care of situations like this is to maintain a list of
> any children created by the parent and make sure they get raped properly
> on exit.


Talk about unfortunate choice of words!

Xho

--
-------------------- 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.
 
Reply With Quote
 
C. Lumina
Guest
Posts: n/a
 
      03-03-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> "C. Lumina" <(E-Mail Removed)> wrote:
>> lekonna wrote:
>>> 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 must say, perhaps you could of chosen a better wording for the
>> subject line!
>>
>> Best way I take care of situations like this is to maintain a list of
>> any children created by the parent and make sure they get raped
>> properly on exit.

>
> Talk about unfortunate choice of words!


AK! Geeze that was a horrible one on my part. (I of course meant to
write "reaped".)

-CL


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Multiprocessing: killing children when parent dies Chris Angelico Python 6 12-07-2011 07:50 PM
killing children spawned by pexpect loorthu Python 0 05-20-2008 12:08 AM
Killing children Laura Conrad Python 15 08-08-2004 02:05 AM
killing my children Oliver Perl Misc 8 06-13-2004 08:52 AM
Killing 1.4.1 parent jvm doesn't kill children also Joel Lindsey Java 1 09-22-2003 03:08 PM



Advertisments