PSIGNAL(9)
π 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. π΄ SIGCONTrestarts 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 forsignum. 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
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1996 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms