PSIGNAL(9)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… PSIGNAL(9) β€” like, the kernel signal posting girlies ✨

Okay so bestie, this is from the Kernel Developer's Manual and it's literally the tea on how the kernel slides signals into threads, processes, and process groups. Buckle up, it's giving low-level realness πŸŽ€


✨ SYNOPSIS ✨

First you gotta summon the headers, no cap:

#include <sys/types.h>
#include <sys/signalvar.h>

Then the function girlies themselves:

void
kern_psignal(struct proc *p, int signum);

void
pgsignal(struct pgrp *pgrp, int signum, int checkctty);

void
tdsignal(struct thread *td, int signum);

🌸 DESCRIPTION 🌸

Okay so these functions are literally the ones that post a signal to a thread or to one or more processes. The signum argument β€” common to all three, iykyk β€” should be in the range [1-NSIG]. Like, that's the vibe check on valid signal numbers πŸ’…

πŸ¦‹ kern_psignal() πŸ¦‹

The kern_psignal() function posts signal number signum to the process represented by the process structure p.

And here's a fun little glow-up story: kern_psignal() used to be called psignal() but got renamed to eliminate a name collision with the libc function of that name and to facilitate code reuse. Iconic rebrand, honestly πŸ‘‘

With a few exceptions noted below, the target process signal disposition is updated and gets marked as runnable, so further handling of the signal is done in the context of the target process after a context switch. But bestie, listen β€” note that kern_psignal() does not by itself cause a context switch to happen. It's not that kind of main character 😌

The target process is not marked as runnable in these cases:

  • The target process is sleeping uninterruptibly. The signal will be noticed when the process returns from the system call or trap. πŸ’€
  • The target process is currently ignoring the signal. πŸ™ˆ
  • If a stop signal is sent to a sleeping process that takes the default action (see sigaction(2)), the process is stopped without awakening it. 😴
  • SIGCONT restarts a stopped process (or puts them back to sleep) regardless of the signal action (e.g., blocked or ignored). πŸ”₯
Also, if the target process is being traced, kern_psignal() behaves as if the target process were taking the default action for signum. This allows the tracing process to be notified of the signal. Like, snitching but make it kernel πŸ•΅οΈβ€β™€οΈ

🌈 pgsignal() 🌈

The pgsignal() function posts signal number signum to each member of the process group described by pgrp. If checkctty is non-zero, the signal will be posted only to processes that have a controlling terminal.

pgsignal() is implemented by walking along the process list headed by the field pg_members of the process group structure pointed at by pgrp and calling kern_psignal() as appropriate. Group-chat energy fr fr β€” it just slides through the member list πŸ“±βœ¨

And plot twist: if pgrp is NULL, no action is taken. Nothing happens. We love a safe exit 🫢

πŸ’œ tdsignal() πŸ’œ

The tdsignal() function posts signal number signum to the thread represented by the thread structure td. Direct message, no group chat πŸ’Œ


πŸ”₯ SEE ALSO πŸ”₯

Go read these next, bestie, they're all part of the lore:


πŸ“œ HISTORY πŸ“œ

The psignal() function was renamed to kern_psignal() in FreeBSD 9.0. A whole era ✨


Okay that's the whole page, you ate that. Go forth and post signals responsibly πŸ’…πŸŒΈ

β€” much love from the Debian girlies, dated July 14, 2023, page PSIGNAL(9) πŸ«ΆπŸŽ€

πŸ“¦ where this page comes from