Handling and propagating signals

Uri Guttman uri at stemsystems.com
Thu Feb 1 18:19:12 GMT 2007


>>>>> "DC" == David Cantrell <david at cantrell.org.uk> writes:

  DC> Someone just reported what I'm inclined to treat as a bug in rsnapshot.
  DC> Boiled down to a minimal example, it's this:

  DC> perl -e '$SIG{TERM} = sub { exit() }; system("sleep 60")'

  DC> Now send that process a SIGTERM.  The perl process promptly exits.  The
  DC> command I ran using system(), however, does not.  I want my signal
  DC> handler to propagate the signal to children as well.

  DC> Because the signal is received while perl is waiting for system() to
  DC> return, I can't see any way in which I can possibly know the child's
  DC> PID without having to grovel through the process table.

you can kill the process group with the killpg system call. at least
solaris doesn't have a command line version but it is trivial in perl:

perl -e 'print "$$\n" ;$SIG{TERM} = sub { exit() }; system("sleep 60")'
28377

perl -e 'kill -15, 28377'

and ps shows no sleep progs (unlike with plain kill).

perldoc -f kill shows that perl's kill supports kill and killpg.

uri

-- 
Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


More information about the london.pm mailing list