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
pidis positive, then signalsiggets sent to the process with the ID specified bypid. ๐ฏ - if
pidequals0, thensiggoes to every process in the process group of the calling process. the whole squad. ๐ - if
pidequals-1, thensigis 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
pidis less than-1, thensiggets sent to every process in the process group whose ID is-pid. ๐ฌ - if
sigis0, 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 beenwait(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, theinitprocess, are those for whichinithas 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)sendsigto 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 callkill(-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 beforekill()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
- Copyright 1992, Drew Eckhardt <drew@cs.colorado.edu>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms