THR_kill(2)
β¨ THR_kill π β bestie, we're sending signals to threads
okay so this is THR_kill(2), a page from the System Calls Manual, and it is genuinely one of my faves because it's SO direct about what it does. let's get into it π«Ά
πΈ NAME πΈ
thr_kill β send signal to thread π
π LIBRARY π
Standard C Library (libc, -lc) β yeah she lives in libc, no cap
β¨ SYNOPSIS β¨
#include <sys/thr.h>
int
thr_kill(long id, int sig);
int
thr_kill2(pid_t pid, long id, int sig);
look at her. two functions. both iconic. one of them lets you point at a different process, which is very main character energy of it π
π DESCRIPTION π
okay so the tea: thr_kill() and thr_kill2() are system calls that let you send a signal β that's the sig argument, bestie β to some threads in a process. not all of them necessarily, just the ones you pick. and yes you DO get to pick, we'll get there.
- for
thr_kill(), the threads you can signal are always limited to the current process. you stay in your lane, you signal your own people. π - for
thr_kill2(), thepidargument is what specifies the process whose threads you wanna signal. so you can reach out to another process. bold. love that for you.
now the fun part β the id argument is literally the "who gets the signal" selector:
- if
idis equal to-1, all threads in the specified process are signalled. everyone. the whole group chat. π - otherwise, only the thread whose thread identifier equals that argument gets signalled. just the one. targeted. precise. it's giving sniper but make it threads π―
and the sig argument defines the delivered signal. it must be a valid signal number, or zero. and zero is the sneaky one β when sig is zero, no signal is actually sent, and the call is used to verify the liveness of the thread. it's a vibe check fr fr. is this thread still alive? ask thr_kill with a zero and find out π«£
oh and one more detail that matters: the signal is delivered with siginfo si_code set to SI_LWP. remember that, iykyk.
π₯ RETURN VALUES π₯
if it goes well, thr_kill() and thr_kill2() return zero. slay. β¨
otherwise -1 is returned, and errno is set to indicate the error. so like, when it's bad, it tells you why. we love an honest king π
π ERRORS π
the thr_kill() and thr_kill2() operations return the following errors:
[EINVAL]β thesigargument is not zero and does not specify valid signal. bestie. that's not a signal. π«[ESRCH]β the specified process or thread was not found. they're gone. ghosted. literally not there. π»
additionally, thr_kill2() may return the following errors:
[EPERM]β the current process does not have sufficient privilege to check existence or send a signal to the specified process. so you tried to reach into somebody else's process and the kernel said no. permission check failed, babes. π
π¦ SEE ALSO π¦
the friend group π
π STANDARDS π
so the thr_kill() and thr_kill2() system calls are non-standard β not in the official standards club, they're doing their own thing β and they're used by the 1:1 Threading Library (libthr, -lthr) to implement IEEE Std 1003.1-2001 (βPOSIX.1β) pthread(3) functionality.
basically they're the backstage crew making the whole pthread situation happen and nobody claps for them. not on my watch. ππ
π heads up bestie: these are non-standard calls, so don't go assuming they exist on every system out there. they're a libthr thing. check your platform, fr fr.
and that's the page!! thr_kill and thr_kill2, sending signals to threads with surgical precision, since forever. this particular page is from the Debian edition and it's dated June 1, 2016 β vintage but still ate, no crumbs left. mwah π πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2016 The FreeBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms