PROC_FIND(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– PROC_FIND(9) β€” bestie's guide to finding procs and pgrps πŸ’–

okay so this is a page from the Kernel Developer's Manual, and honestly? it's giving "short but essential" ✨ like it's not long but it ate.


🌸 NAME 🌸

proc_find, pgrp_find β€” your two new besties for finding a process or a process group 🫢


✨ SYNOPSIS ✨

#include <sys/proc.h>

struct proc *
proc_find(pid_t pid);

struct pgrp *
pgrp_find(pid_t pgid);

extern kmutex_t *proc_lock;

like yes, that's the whole vibe. three lines of declarations and we're off πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so listen: proc_find() and pgrp_find() are the functions that go retrieve your process and process group structures for you πŸ‘‘ β€” specifically, proc_find() takes a process ID (pid) and pgrp_find() takes a process group ID (pgid).

and here's the part you cannot skip, bestie, no cap: both functions must be called by holding a mutex(9) on proc_lock. both of them. every single time. this is not optional, this is not a "maybe", this is the whole rules of the game πŸ”₯


πŸ’€ RETURN VALUES πŸ’€

upon successful completion, the described functions return a pointer to either struct proc or struct pgrp 🌈 β€” so like, congrats, you got your struct, iconic.

otherwise, if the requested ID was not found, NULL is returned 😭 so like, check that pointer. fr fr.


πŸŽ€ SEE ALSO πŸŽ€


ngl the proc_lock thing is the main character of this whole page β€” hold the mutex, or don't come crying to me πŸ™ˆ

and that's the whole page, bestie! this gem is from Debian, dated July 1, 2010, and it lives in the Kernel Developer's Manual section πŸ’œ mwah, go hold that lock 🧚✨

πŸ“¦ where this page comes from