Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kill -0 please #471

Open
ale5000-git opened this issue Oct 26, 2024 · 3 comments
Open

Fix kill -0 please #471

ale5000-git opened this issue Oct 26, 2024 · 3 comments

Comments

@ale5000-git
Copy link

It would be nice to have kill -0 working even if process_architecture_matches_current fails.
Currently it say: can't kill pid 20808: Permission denied

kill -0 doesn't send any signal, isn't possible to make it working even with bitness mismatch?

@rmyorston
Copy link
Owner

I don't think any fix is necessary. POSIX says of the kill utility:

For each pid operand, the kill utility shall perform actions equivalent to the kill() function...

And of the kill() function it says:

If sig is 0 (the null signal), error checking is performed but no signal is actually sent.

So if you don't have permission to signal a process kill -0 should report the error and fail, even though no signal is sent.

And indeed, that's what I see on Linux:

$ /usr/bin/kill -0 1; echo $?
kill: sending signal to 1 failed: Operation not permitted
1
$ 

@ale5000-git
Copy link
Author

ale5000-git commented Oct 27, 2024

kill -9 can kill even if there is a bitness mismatch.
I think it is more useful to use kill -0 to check if a process is active (like as in #470) as you can NOT use ps -p $pid or test -d /proc/$pid in BusyBox for Windows (and wait is blocking).

Or maybe what about -0 to check if the process is active and -00 to check if the normal kill would work?

@ale5000-git
Copy link
Author

ale5000-git commented Oct 27, 2024

These are the updated POSIX pages:
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/kill.html
https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html

Quote:

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>](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html) 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.

The most relevant part is: The null signal can be used to check the validity of pid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants