Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Stopping subprocesses

by cdarke (Prior)
on Aug 24, 2010 at 10:05 UTC ( #856895=note: print w/replies, xml ) Need Help??

in reply to Stopping subprocesses

For background information, it might be worth reading (on Linux) man 7 signal.

When you hit CTRL-C then a SIGINT is sent to all the processes in the foreground group. When you use the shell built-in command kill the shell will send SIGTERM. If you are getting different behavior with different signals then someone must be trapping the SIGTERM. Ignore signals are usually inherited.

In addition, usually, when a parent dies it sends a SIGHUP to the child, which might kill the child, again depending on signal handling, for example using the nohup program or trapping SIGHUP will prevent this.

Keeping track of PIDs should not be difficult, it is the return value of fork in the parent. Provided the children of B are not ignoring hangups, then killing B should bring the children down as well.

Alternatively, from kill:
"Unlike in the shell, if SIGNAL is negative, it kills process groups instead of processes."
Provided the children have not switched process groups (which a daemon might do) then that might be a safer bet. It is not worth calling a shell's version of kill using system when there is one built-in to perl.

Replies are listed 'Best First'.
Re^2: Stopping subprocesses
by rowdog (Curate) on Aug 24, 2010 at 11:47 UTC

    I agree, kill is the way to go. And here's a link to Debian's current man 7 signal.

Re^2: Stopping subprocesses
by James Board (Beadle) on Aug 24, 2010 at 13:57 UTC
    Disagree. Keeping track of PIDs is difficult. If A starts B and B starts C, and C starts D, etc, how does A figure out all of those PIDs? Does each of B, C, D, etc open a socket to A and send the child PIDs?
Re^2: Stopping subprocesses
by James Board (Beadle) on Aug 24, 2010 at 14:21 UTC
    I appreciate the Unix signals lecture. In my simple example, C isn't ignoring hangups, yet when I kill B, it's child C isn't killed. So I'm not sure you read all of my original question.
Re^2: Stopping subprocesses
by James Board (Beadle) on Aug 24, 2010 at 14:23 UTC
    These last two replies should be in reference to cdarke's post. But the perlmonks website put them somewhere else: I'm not sure if this is because of a bug in the perlmonks website, or mozilla.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://856895]
[james28909]: i guess i should have done it in perl. i bet it woulnt have taken me 5 hours to figure out haha
[choroba]: In the end, I was able to upgrade Perl from 5.8.3 to 5.22 and install Net::SFTP::Foreign , at least for the task involved
[james28909]: what would be the best way to capture that stream with perl? ffmpeg args -rtp rtp://
[LanX]: if I was forced to talk about all security risks I encountered oO
[james28909]: if i did that with ffmpeg, i could then listen on the port with perl right?
[LanX]: one of my clients filtered a menu linking to Web pages according to user rights. .. but he didn't secure the access to those unlisted pages

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-05-22 21:48 GMT
Find Nodes?
    Voting Booth?