pthread_kill(3)
๐ pthread_kill โ bestie, we're sending signals to a thread now ๐
okay so this page lives in Library Functions Manual, it's a section 3 situation, and it's all about yeeting a signal at one specific thread. let's get into it ๐ซถ
โจ NAME โจ
pthread_kill โ send a signal to a thread
๐ LIBRARY ๐
POSIX threads library โ link it with libpthread, -lpthread.
๐ธ SYNOPSIS ๐ธ
#include <signal.h>
int pthread_kill(pthread_t thread, int sig);
๐ Feature Test Macro Requirements for glibc (see feature_test_macros(7)): ๐
pthread_kill():
_POSIX_C_SOURCE >= 199506L || _XOPEN_SOURCE >= 500
like, that's the whole vibe check gate right there. no cap. ๐
๐ซ DESCRIPTION ๐ซ
So pthread_kill() sends the signal sig to thread โ and thread has to be a thread in the same process as whoever's calling. The signal gets asynchronously directed to that thread. asynchronous. it's giving mystery, it's giving "you'll get it when you get it". ๐
And here's the little trick that everyone loves: if sig is 0, no signal is actually sent, but the error checking still happens. it's the "just checking, no thoughts, no signal" mode. lowkey iconic. โจ
๐ฆ RETURN VALUE ๐ฆ
Slay โ returns 0.
Not slay โ returns an error number, and no signal gets sent. periodt. ๐ซ
๐ฅ ERRORS ๐ฅ
EINVALโ an invalid signal was specified. bestie. that's not a real signal. we can't send that. ๐
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
- Interface:
pthread_kill() - Attribute: Thread safety
- Value:
MT-Safe
so yeah, it's MT-Safe โ she's safe, she's fine, she can hang with the other threads. ๐
๐ VERSIONS ๐
The glibc implementation of pthread_kill() gives an error (EINVAL) if you try to send either of the real-time signals used internally by the NPTL threading implementation. those are NPTL's signals, not yours, hands off. see nptl(7) for the details. ๐ง
POSIX.1-2008 recommends that if an implementation detects you using a thread ID after the end of its lifetime, pthread_kill() should return the error ESRCH. The glibc implementation returns this error in the cases where an invalid thread ID can be detected. But โ and this is the important part โ POSIX also says that trying to use a thread ID whose lifetime has ended produces undefined behavior, and using an invalid thread ID in a call to pthread_kill() can, for example, cause a segmentation fault. ๐
girl. do not use a dead thread ID. that is not a vibe, that is a crash. ๐
โญ STANDARDS โญ
POSIX.1-2008.
๐ HISTORY ๐
POSIX.1-2001. she's been around, she's a classic, she's an OG. ๐
๐ NOTES ๐
Signal dispositions are process-wide, okay? so if a signal handler is installed, the handler will be invoked in the thread thread โ in that thread specifically. but if the disposition of the signal is "stop", "continue", or "terminate", then that action is gonna affect the whole process. everybody. the entire group chat. no one gets left out of that one. ๐ญ
๐ซถ SEE ALSO ๐ซถ
kill(2), sigaction(2), sigpending(2), pthread_self(3), pthread_sigmask(3), raise(3), pthreads(7), signal(7)
and that's the whole page, bestie ๐ this one's from Linux man-pages 6.20, dated 2025-05-17, and it's the pthread_kill(3) page โ go forth and signal 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