PSIGNAL(9)

πŸ’– PSIGNAL πŸ’–

okay bestie, welcome to the kernel developer's manual for PSIGNAL(9) β€” yes it's a section 9 page, yes that means it's kernel-internal stuff, and yes you're gonna understand it. periodt.


✨ NAME ✨

psignal, kern_psignal, pgsignal, gsignal, tdsignal β€” post a signal to a thread, a process, or a whole process group 🫢


🌸 SYNOPSIS 🌸

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

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

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

void
gsignal(int pgid, int signum);

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So the way this works is: these functions post a signal to a thread, or to one or more processes. And the signum argument β€” the one that literally every single one of these functions has, no cap β€” has to be in the range [1-NSIG]. That's the vibe check right there. πŸŽ€

πŸ’… kern_psignal()

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

ngl, this one has lore: kern_psignal() used to be called psignal() but it got renamed so it would stop having a name collision with the libc function of that same name, and also to make code reuse easier. iconic behavior honestly.

With a few exceptions (we're getting to them, don't worry), the target process's signal disposition gets updated and it gets marked as runnable β€” so the actual further handling of the signal happens in the context of the target process, after a context switch. ✨

⚠️ But heads up bestie: kern_psignal() does not by itself cause a context switch to happen. It just sets things up. Don't @ me.

🚫 when the target process is NOT marked as runnable

  • 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 (peep 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 β€” like, even if it's blocked or ignored. fr fr, it does not care.

πŸ” traced processes

If the target process is being traced, kern_psignal() behaves as if the target process were taking the default action for signum. This is so the tracing process can be notified of the signal. teamwork! 🀝

πŸŽ€ 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 only be posted to processes that have a controlling terminal. picky, but valid.

Implementation tea: pgsignal() works 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. If pgrp is NULL, no action is taken. just nothing. silence. πŸ™ˆ

⭐ gsignal()

The gsignal() function posts signal number signum to each member of the process group identified by the group id pgid.

How? gsignal() first finds the group structure associated with pgid, then invokes pgsignal() with the argument checkctty set to zero. If pgid is zero, no action is taken. πŸ«₯

🌈 tdsignal()

The tdsignal() function posts signal number signum to the thread represented by the thread structure td. short, sweet, targeted. main character energy. πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯


πŸ‘‘ HISTORY πŸ‘‘

The psignal() function was renamed to kern_psignal() in FreeBSD 9.0. glow-up era.


and that's the whole page bestie!! πŸ’œ this one came from the Debian crew, dated October 8, 2011, and it lives in section PSIGNAL(9). go post some signals responsibly. mwah πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from