[ruby-core:82075] [Ruby trunk Bug#13501] Process.kill behaviour for negative pid is not documented and may be wrong

From: shyouhei@...
Date: 2017-07-15 11:24:39 UTC
List: ruby-core #82075
Issue #13501 has been updated by shyouhei (Shyouhei Urabe).


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.

----------------------------------------
Bug #13501: Process.kill behaviour for negative pid is not documented and may be wrong
https://bugs.ruby-lang.org/issues/13501#change-65807

* Author: toy (Ivan Kuchin)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin14]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Following code will not fail and will print "TERM caught by NN" both for spawned and forked processes:

~~~ ruby
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](https://linux.die.net/man/2/kill), [osx](https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/kill.2.html) and [POSIX](http://pubs.opengroup.org/onlinepubs/009695399/functions/kill.html) documentation for `kill` describes behaviour for negative pid is to send signal to process group.

As `Process.kill` is [using `killpg`](https://github.com/ruby/ruby/blob/e97ac02f8466275732a33f704480c03da722f485/signal.c#L464) 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`.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next