PTHREAD_KILL(3POSIX)
π PTHREAD_KILL β okay bestie, let's talk signals
so this is page PTHREAD_KILL(3POSIX) from the POSIX Programmer's Manual, and it's giving "one thread, one very targeted vibe check." iykyk. let's go π«Ά
β¨ PROLOG β¨
okay so real talk before we start: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. OR the interface might just not be implemented on Linux at all. π so like, check first, bestie.
πΈ NAME πΈ
pthread_kill β send a signal to a thread β¨
(yeah. that's it. that's the whole job. iconic.)
π SYNOPSIS π
#include <signal.h>
int pthread_kill(pthread_t thread, int sig);
π¦ DESCRIPTION π¦
so the pthread_kill() function shall request that a signal be delivered to the specified thread. that's the whole assignment. very main character, very direct. π
and β just like in kill() β if sig is zero, error checking shall be performed but no signal shall actually be sent. so it's like, the vibe check without the actual consequence. lowkey the polite version. π
π RETURN VALUE π
upon successful completion, the function shall return a value of zero. slay. β¨
otherwise, the function shall return an error number. and if pthread_kill() fails, no signal shall be sent β so like, no accidental chaos, we love that for us. π«Ά
π₯ ERRORS π₯
the pthread_kill() function shall fail if:
EINVALβ the value of thesigargument is an invalid or unsupported signal number. not a real signal, bestie, we can't work with that. π
and here's a fun lil fact: the pthread_kill() function shall not return an error code of [EINTR]. nope. never. not a thing.
the following sections are informative. (aka: the gossip, not the law β¨)
π EXAMPLES π
None. π
literally none. the standard said "no thoughts, head empty." we move on. π
π APPLICATION USAGE π
okay so here's where it gets fun. pthread_kill() provides a mechanism for asynchronously directing a signal at a thread in the calling process. so like, you can point a signal at one specific thread instead of just yelling into the void of the whole process. targeted. precise. π
this could be used, for example, by one thread to affect broadcast delivery of a signal to a set of threads. cute little group chat coordination moment. π£
but WAIT β super important, don't miss this: note that pthread_kill() only causes the signal to be handled in the context of the given thread. the signal action (termination or stopping) affects the process as a whole. so like, you aimed at one thread but the consequence is giving whole-process energy. π« keep that in mind fr fr.
π§ RATIONALE π§
if an implementation detects use of a thread ID after the end of its lifetime, it is recommended that the function should fail and report an [ESRCH] error. (that's "no such process," for the uninitiated β¨)
now here's the messy part. existing implementations vary on the result of a pthread_kill() with a thread ID indicating an inactive thread (a terminated thread that has not been detached or joined). some indicate success on such a call, while others give an error of [ESRCH]. so like... it's giving "choose your own adventure" and honestly? not the vibe we're going for in a standard. π
since the definition of thread lifetime in this volume of POSIX.1β2017 covers inactive threads, the [ESRCH] error as described is inappropriate in this case. in particular, this means that an application cannot have one thread check for termination of another with pthread_kill(). nope. not a tool for that. don't try it. π
β FUTURE DIRECTIONS β
a future version of this standard may require that pthread_kill() not fail with [ESRCH] in the case of sending signals to an inactive thread (a terminated thread not yet detached or joined) β even though no signal will be delivered because the thread is no longer running.
so like, future-her might be nicer about it. but no promises. π
π SEE ALSO π
kill()pthread_self()raise()- the Base Definitions volume of POSIX.1β2017,
<signal.h>
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (it's the final boss, basically π) the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! π brought to you by IEEE/The Open Group, 2017, on page PTHREAD_KILL(3POSIX) β stay safe, send your signals responsibly, and don't be checking thread lifetimes with this function. periodt. π
β¨π¦
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms