kill(2)

๐Ÿ’… kill(2) โ€” bestie edition โœจ

okay so real talk: this is kill(2), from the System Calls Manual, and no, it's not as violent as it sounds, it's just how Unix says "hey. heads up." ๐Ÿซถ

NAME โ€” kill โ€” send signal to a process ๐Ÿ“ฃ


๐Ÿ“š LIBRARY

Standard C library (libc, -lc). the classic. the blueprint. the moment. โœจ


๐ŸŒธ SYNOPSIS

#include <signal.h>

int kill(pid_t pid, int sig);

๐ŸŽ€ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

kill():
    _POSIX_C_SOURCE

๐Ÿฆ‹ DESCRIPTION

so the kill() system call can send any signal to any process group or process. it's giving universal remote energy. ๐ŸŒˆ

  • if pid is positive, then signal sig gets sent to the process with the ID specified by pid. ๐ŸŽฏ
  • if pid equals 0, then sig goes to every process in the process group of the calling process. the whole squad. ๐Ÿ’–
  • 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), but see below. ๐Ÿ™ˆ (init is protected, bestie, we'll get to why)
  • if pid is less than -1, then sig gets sent to every process in the process group whose ID is -pid. ๐Ÿ“ฌ
  • if sig is 0, then likeโ€ฆ no signal is actually sent, but the existence and permission checks still happen. so it's a little vibe check ๐Ÿ’… you can use it to see whether a process ID or process group ID exists and whether you're allowed to signal it. no cap, this is the classic "are you alive and can I talk to you" move.

now, the โœจ permission girlies โœจ โ€” for a process to have permission to send a signal, it has to either be privileged (under Linux: have the CAP_KILL capability in the user namespace of the target process), or the real or effective user ID of the sending process must equal the real or saved set-user-ID of the target process. in the case of SIGCONT, it's enough that the sending and receiving processes belong to the same session. ๐Ÿซ‚ (historically the rules were different โ€” see HISTORY, it's a whole saga.)


๐Ÿ”ฅ RETURN VALUE

on success, zero comes back. ๐ŸŽ‰ and if signals were sent to a process group, "success" means that at least one signal was delivered (not all of them โ€” set your expectations accordingly, bestie).

on error, -1 comes back and errno is set to tell you what went wrong. ๐Ÿ˜ญ


๐Ÿ’€ ERRORS

  • EINVAL โ€” an invalid signal was specified. like girl, that's not a signal. ๐Ÿ™…
  • EPERM โ€” the calling process does not have permission to send the signal to any of the target processes. it's giving locked out of the group chat. ๐Ÿ”’
  • ESRCH โ€” the target process or process group does not exist. heads up though: an existing process might be a zombie โ€” a process that has terminated execution but hasn't been wait(2)ed for yet. so it's technically still on the roster but not... present. ๐Ÿ’€

โญ STANDARDS

POSIX.1-2024. periodt. ๐Ÿ‘‘


๐ŸŒˆ HISTORY

4.3BSD, SVr4, POSIX.1-1988. the ancestors ate. ๐Ÿงš

๐Ÿ“ Linux notes

across different kernel versions, Linux has enforced different rules for the permissions required for an unprivileged process to send a signal to another process. strap in:

  • in Linux 1.0 to 1.2.2, a signal could be sent if the effective user ID of the sender matched the effective user ID of the target, or if the real user ID of the sender matched the real user ID of the target. ๐Ÿค
  • from Linux 1.2.3 until 1.3.77, a signal could be sent if the effective user ID of the sender matched either the real or effective user ID of the target. ๐Ÿ”„
  • the current rules, which conform to POSIX.1, were adopted in Linux 1.3.78. glow up complete โœจ

๐Ÿ’œ NOTES

  • the only signals that can be sent to process ID 1, the init process, are those for which init has explicitly installed signal handlers. this is done to make sure the system isn't brought down accidentally. so yeah โ€” don't be the reason the whole machine clocks out. ๐Ÿ›‘๐Ÿ˜ญ
  • POSIX.1 requires that kill(-1,sig) send sig to all processes that the calling process may send signals to, except possibly for some implementation-defined system processes. Linux allows a process to signal itself, but on Linux the call kill(-1,sig) does not signal the calling process. interesting, right? ๐Ÿ™ˆ
  • POSIX.1 requires that if a process sends a signal to itself, and the sending thread doesn't have the signal blocked, and no other thread has it unblocked or is waiting for it in sigwait(3), then at least one unblocked signal must be delivered to the sending thread before kill() returns. so it's not just fire-and-forget, bestie, it's fire-and-confirm. ๐Ÿ”ฅ

๐Ÿ› BUGS

in Linux 2.6 up to and including Linux 2.6.7, there was a bug that meant when sending signals to a process group, kill() failed with the error EPERM if the caller didn't have permission to send the signal to any (rather than all) of the members of the process group. (yes, any instead of all. the logic was inverted. iconic behavior, honestly. ๐Ÿ’€)

and notwithstanding that error return, the signal was still delivered to all of the processes for which the caller had permission to signal. so it errored and it worked. the duality of man. ๐Ÿ™ƒ


๐Ÿ‘€ SEE ALSO

kill(1), pidfd_send_signal(2), signal(2), tkill(2), _exit(3), exit(3), killpg(3), sigqueue(3), capabilities(7), credentials(7), signal(7)


and that's the whole page, bestie!! this one came from Linux man-pages 6.20, dated 2026-06-05 โ€” so if you're reading this, shoutout to the man-pages girlies for keeping the docs immaculate. ๐Ÿซถโœจ๐Ÿ’– go signal something responsibly, mwah! ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms