THR_KILL(2)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… THR_KILL(2) β€” like, the thread-signalling girlies πŸ’…

okay bestie, welcome to THR_KILL(2), the System Calls Manual page where we learn how to slide a signal into one specific thread instead of dumping it on the whole entire process. iykyk. πŸ’Œ


✨ NAME ✨

thr_kill β€” send signal to thread 🎯


🫢 LIBRARY 🫢

Standard C Library (libc, -lc) β€” she's built in, no extra shopping required. πŸ’–


🌸 SYNOPSIS 🌸

#include <sys/thr.h>

int
thr_kill(long id, int sig);

int
thr_kill2(pid_t pid, long id, int sig);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the thr_kill() and thr_kill2() system calls let you send a signal β€” the one you specify with the sig argument β€” to some threads in a process. not all of them. some. targeted. main character selectivity. ✨

quick vibe check on who's allowed to get signalled:

  • with thr_kill(), the signalled threads are always limited to the current process. she stays home. no wandering. 🏠
  • with thr_kill2(), the pid argument specifies the process whose threads you wanna signal. so you can go visit. 🌍

now, the id argument is the whole "which thread tho" situation:

  • if id is equal to -1, all threads in the specified process are signalled β€” it's giving group chat blast πŸ“’
  • otherwise, only the thread with the thread identifier equal to the argument is signalled β€” it's giving DM πŸ’Œ

and the sig argument defines the delivered signal. it must be a valid signal number or zero. yes, zero is a real option, and here's the tea: in that case no signal is actually sent, and the call is used to verify the liveness of the thread. basically a "u up?" text. πŸ‘€πŸ«Ά

one more detail, don't skip it: the signal is delivered with siginfo si_code set to SI_LWP. πŸ“Ž


πŸŽ€ RETURN VALUES πŸŽ€

if successful, thr_kill() and thr_kill2() will return zero. otherwise -1 is returned, and errno is set to indicate the error. slay when it works, 😭 when it doesn't.


πŸ”₯ ERRORS πŸ”₯

the thr_kill() and thr_kill2() operations return the following errors:

  • [EINVAL] β€” the sig argument is not zero and does not specify a valid signal. 🚫
  • [ESRCH] β€” the specified process or thread was not found. she's not here, babe. πŸ’€

additionally, the 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. πŸ”’ nope, not allowed, no cap.

🌈 SEE ALSO 🌈

_umtx_op(2), kill(2), thr_exit(2), thr_new(2), thr_self(2), thr_set_name(2), pthread_kill(3), signal(3)

the whole friend group fr fr πŸ«‚


πŸ‘‘ STANDARDS πŸ‘‘

the thr_kill() and thr_kill2() system calls are non-standard β€” they're built diff, they don't follow the crowd πŸ’… β€” and are used by the 1:1 Threading Library (libthr, -lthr) to implement IEEE Std 1003.1-2001 ("POSIX.1") pthread(3) functionality. iconic behaviour, honestly. ⭐


⭐ HISTORY ⭐

the thr_kill() and thr_kill2() system calls first appeared in FreeBSD 5.2. she's been around. vintage. πŸŽ€


ngl bestie, sig of zero is genuinely useful β€” it's the liveness check β€” but don't go thinking you can send just any number in there, EINVAL will humble you real quick. πŸ™ˆ

that's the whole page!! mwah πŸ’‹ this was THR_KILL(2) from Debian, dated May 5, 2020 β€” go be iconic with your threads, ily, bye πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from