by burke · 8y ago · 0 comments
`kill(-1, ...)` would signal pgid 1, which would be the process group of init.
From a quick scan of the issue, it looks like maybe nix is using macOS's sandbox feature somehow, maybe that creates a process namespace of sorts and makes `kill(-1, ...)` useful?
EDIT: nvm, there's a special-case for -1:
> If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init)...
I'm surprised this isn't encountered by more people: that seems useful.
It's useful like an atom bomb is useful - a really heavy-handed approach. Usually this is a smell that indicates forking processes are not communicating well.
It's much better to have well-behaved processes. Send SIGTERM to the parent process, allow the parent to perform cleanup of its own children recursively.
It's intended for when you reboot the system, to get every process to quit. And for when you logout, to close everything you have running.
So yes, useful.
When logging out via the OS supplied method this is handled for the user. Why on earth would a user have to call kill -1 on logout?
My comment was from the perspective of an application developer.
> this is handled for the user.
And that's how - they call that syscall.
Maybe you didn't realize. Notice the parenthesis? It's a function call in a programming language. The command line program is just a passthrough to the syscall.
And when rebooting you do need the command line program, so preventing it from passing -1 through doesn't make sense either.