Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Perl's kill(): How to check if process group exists?

by saintmike (Vicar)
on Jul 31, 2011 at 19:29 UTC ( #917717=perlquestion: print w/replies, xml ) Need Help??
saintmike has asked for the wisdom of the Perl Monks concerning the following question:

I want to send a signal to a process group, but up-front I'd like to know if it has a chance of succeeding.

Background: perl abstracts the system call killpg() and warps it into kill() with negative signal numbers. So, if you call kill(-15, $pid), perl translates it to killpg(15, $pid) on systems that support killpg().

Problem is that in order to run killpg(0, $pid), I'd have to call kill(-0, $pid) which is the same as kill(0, $pid) and won't trigger the special killpg(0, $pid) behavior.

So, there's no way to check if a process is up but hasn't called POSIX::setsid() or POSIX::setpgid() yet, causing kill(15, $pid) to succeed but kill(-15, $pid) to fail.

Any way around that? I could roll my own killpg() XS module, but I'd rather have it portable across Unix flavors and, ideally, use something that already comes with perl.

Replies are listed 'Best First'.
Re: Perl's kill(): How to check if process group exists?
by zentara (Archbishop) on Aug 01, 2011 at 13:50 UTC
Re: Perl's kill(): How to check if process group exists?
by repellent (Priest) on Aug 07, 2011 at 09:45 UTC
    I'm curious if kill(-0.1, $pid) would work for you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://917717]
Approved by davies
[jedikaiti]: 'elo Monks
[perldigious]: https://www.xkcd. com/1876/
[perldigious]: https://www.xkcd. com/1877/
[perldigious]: Good times. :-)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2017-08-16 15:42 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (269 votes). Check out past polls.