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