in reply to How to kill forked process

"All I want to do is ..."

To be honest, that's not quite as easy as your pseudo-code implies.

if (my $pid = fork()) { # parent monitor($pid); } elsif (defined $pid) { # child exec(@command); } else # fork failed. { # How do you want to handle this? }
Of course, monitor is the tough part. You'll probably need to set a signal handler for SIGCHLD - so you'll know when the child exits. You'll want to probably use Term::ReadKey, although I'm not sure if ReadKey will return if interrupted with a signal. And then, if you do get the right key, you can use kill to kill the $pid we got from fork.

I hope this helps, barring some more adventerous monk writing a more complete example.

Replies are listed 'Best First'.
Re^2: How to kill forked process
by redss (Monk) on Feb 17, 2005 at 05:25 UTC
    thanks for your reply, but I goofed in my problem description. See my reply to the next post.

    (why do I have to reply to a particular post, instead of the general thread?)