kill -0 <pid> --- side effect or supported
Dirk-Willem van Gulik
dirkx at webweaving.org
Sun Mar 5 21:09:19 UTC 2017
> On 3 Mar 2017, at 23:42, Ngie Cooper (yaneurabeya) <yaneurabeya at gmail.com> wrote:
>
>>
>> On Mar 3, 2017, at 14:30, Rodney W. Grimes <freebsd-rwg at pdx.rh.CN85.dnsmgr.net> wrote:
>>
>> -- Start of PGP signed section.
>> [ Charset UTF-8 unsupported, converting... ]
>>>
>>>> On Mar 3, 2017, at 14:12, Dirk-Willem van Gulik <dirkx at webweaving.org> wrote:
>>>>
>>>> I regularly use 'kill -0 <pid>' on FreeBSD as a way to test if a certain process is still running (but without actually sending the signal). And I think it has worked reliably since the mid 80's.
>>>>
>>>> Is it actually a properly supported use - as I recently happened to notice that it does not seem to be all that documented in kill(
>>>
>>> It better work. I have code that relies on it :)?
>>>
>>> It does work as you noted, according to truss:
>>>
>>> # sudo truss -ff kill -0 1 2>&1
>>> ...
>>> 79940: kill(1,0) = 0 (0x0)
>>> ?
>>> #
>>>
>>> As noted in kill(2), this is one of the valid values:
>>>
>>> a group of processes. The sig argument may be one of the signals
>>> specified in sigaction(2) or it may be 0, in which case error checking is
>> ^^^^^^^^^^^^^^^^
>>
>> That bit of information should be promoted from kill(2) to kill(1) by
>> adding 0 to the list as ?.
>
> Actually… it is mentioned in kill(1) — you just have to read between the lines:
>
> -signal_number
> A non-negative decimal integer, specifying the signal to be sent
> instead of the default TERM.
>
> 0 is technically a non-negative real number.
>
> It might be a good idea to clarify this point/behavior by pointing to kill(2) for the signal behavior/description noted above.
Posix @ Opengroup says:
http://pubs.opengroup.org/onlinepubs/009695399/functions/kill.html
The kill() function shall send a signal to a process or a group of processes specified by pid. The signal to be sent is specified by sig and is either one from the list given in <signal.h> or 0. If sig is 0 (the null signal), error checking is performed but no signal is actually sent. The null signal can be used to check the validity of pid.
I guess this could be added - with perhaps the note/warning on the 'zombie' processes - as this is subtly different between unixes.
Dw
More information about the freebsd-hackers
mailing list