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 #1

Updated by toy (Ivan Kuchin) over 7 years ago

  • ruby -v changed from ruby 2.2.7p470 (2017-03-28 revision 58194) [x86_64-darwin14] to ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin14]

Updated by shevegen (Robert A. Heiler) over 7 years ago

Agreed - the behaviour should also be documented. Not that I think anyone wants to use a
negative PID (how is that even possible) but simply because one could pass -1 or -42 or
whatever.

Updated by toy (Ivan Kuchin) over 7 years ago

Negative pid will send signal to the process group.
And specifically -1 will send it nearly system wide if the process user has root privileges.

Updated by shyouhei (Shyouhei Urabe) over 7 years ago

We looked at this issue at yesterday's developer meeting and agreed that the acceptance of negative pid shall be documented.

But killing other process is ultimately dome by the platform. It seems not possible to completely remove platform dependency.

Updated by toy (Ivan Kuchin) over 7 years ago

What do you think about intercepting negative pid and also using it to set negative, so that behaviour is consistent on ruby side and killpg is used when needed?

Actions #6

Updated by jeremyevans (Jeremy Evans) over 5 years ago

  • Status changed from Open to Closed

Applied in changeset git|b1a2eddbfcb883c363bd67858a4dc739f4755775.


Document acceptance of negative pid in Process.kill [ci skip]

Fixes [Bug #13501]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0