Project

General

Profile

Actions

Bug #13501

closed

Process.kill behaviour for negative pid is not documented and may be wrong

Added by toy (Ivan Kuchin) over 7 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin14]
[ruby-core:80838]

Description

Following code will not fail and will print "TERM caught by NN" both for spawned and forked processes:

pid = spawn 'ruby', '-e', <<-'RUBY', :pgroup => true
  trap('TERM'){ print "TERM caught by #{$$}\n" }
  fork
  sleep 10
RUBY
sleep 1
Process.kill('TERM', -pid)

Documentation explains such behaviour for using negative signal (or a string starting with '-'), but not negative pid.

linux, osx and POSIX documentation for kill describes behaviour for negative pid is to send signal to process group.

As Process.kill is using killpg if it is defined, the behaviour may be undefined on systems with killpg present but kill not conforming to POSIX specification.
Also sending negative signal with negative pid will call killpg with negative pid.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0