PHOLD(9)

πŸ’– PHOLD β€” hold a process πŸ’–

okay bestie, so we're in the kernel dev manual today and the whole vibe is: how do you keep a process from dipping out before you're done with it?? that's it. that's the page. let's get into it 🫢


✨ SYNOPSIS ✨

#include <sys/proc.h>

PHOLD(struct proc *p);

_PHOLD(struct proc *p);

PRELE(struct proc *p);

_PRELE(struct proc *p);

PROC_ASSERT_HELD(struct proc *p);

PROC_ASSERT_NOT_HELD(struct proc *p);

🌸 DESCRIPTION 🌸

so like. the PHOLD() macro bumps up the hold count of a process, and the PRELE() macro brings that hold count back down. that's the whole dynamic. it's giving ✨reference counting✨ but make it processes.

now here's the tea β˜• β€” if a process with a non-zero hold count tries to exit, it does NOT get to leave. nope. it will sleep until its hold count hits zero, and only then does the kernel begin releasing resources associated with the process. it's literally waiting at the door like "bestie let me out" and the kernel is like "not until everyone lets go of you πŸ™ˆ".

which brings us to the very important part, and I need you to lock in for this one:

once a process has started exiting, it is invalid to increase its hold count. so callers must NOT attempt to hold a process that has the P_WEXIT flag set. no. don't. that's the rule. πŸ’€

also, little fun fact for your notes app: the VM daemon will not swap out the kernel stack of a thread belonging to a process with a non-zero hold count. so while you're holding on, that stack is staying right where it is, no cap πŸ‘‘

and the underscore twins!! the _PHOLD() and _PRELE() macros are identical to PHOLD() and PRELE() β€” same energy, same behavior β€” EXCEPT they must be called with the process lock held. that's the only difference. one (1) difference. periodt πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Mark Johnston <markj@FreeBSD.org>. iconic of him honestly 🌈


okay and that's the whole page, bestie!! you're officially caught up on process holding πŸŽ€βœ¨

Debian 🌸 November 7, 2015 πŸ¦‹ PHOLD(9) πŸ’– mwah, go hold some processes responsibly 🫢

πŸ“¦ where this page comes from