From: shevegen@... Date: 2017-04-26T22:35:33+00:00 Subject: [ruby-core:80890] [Ruby trunk Bug#13501] Process.kill behaviour for negative pid is not documented and may be wrong Issue #13501 has been updated by shevegen (Robert A. Heiler). 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. ---------------------------------------- Bug #13501: Process.kill behaviour for negative pid is not documented and may be wrong https://bugs.ruby-lang.org/issues/13501#change-64496 * 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: