PROCCTL(2)
π PROCCTL(2) π
so this is procctl from the System Calls Manual, and bestie, it is a whole vibe β it's how you get hands-on with processes. buckle up. π
β¨ NAME β¨
procctl β control processes π«Ά
π LIBRARY π
Standard C Library (libc, -lc) β yeah, the classic. no extra lib needed, she's built in. π
π§ SYNOPSIS π§
#include <sys/procctl.h>
int
procctl(idtype_t idtype, id_t id, int cmd, void *data);
πΈ DESCRIPTION πΈ
okay so the procctl() system call is your main character moment for controlling processes. the idtype and id arguments are how you pick which processes you're controlling. and here's the tea: if multiple processes match that identifier, procctl will do a "best effort" and try to control as many of the selected processes as it possibly can. an error only comes back if literally zero of the selected processes actually completed the request. ngl that's forgiving of her.
these are the identifier types she supports:
P_PIDβ control the process with the process IDid. just the one. πP_PGIDβ control processes belonging to the process group with the IDid. the whole squad. π
the actual control request you're doing is picked by the cmd argument. here are the commands she supports:
π₯ PROC_ASLR_CTL π₯
controls the Address Space Layout Randomization (ASLR) in the program images created by execve(2) in the specified process β or in its descendants, as long as they didn't change the control and didn't modify it by other means. so like, it's giving β¨generationalβ¨ energy.
the data parameter must point to the integer variable holding one of these values:
PROC_ASLR_FORCE_ENABLEβ requesting that ASLR is enabled after execution, even if it's disabled system-wide. but heads up: the image flag and set-uid might still prevent ASLR enablement. so don't come for her if it doesn't work, ok? πPROC_ASLR_FORCE_DISABLEβ requesting that ASLR is disabled after execution. same notes as forPROC_ASLR_FORCE_ENABLEapply. πPROC_ASLR_NOFORCEβ just use the system-wide configured policy for ASLR. lowkey the chill option. π¦
β¨ PROC_ASLR_STATUS β¨
returns the current status of ASLR enablement for the target process. the data parameter must point to the integer variable, where one of the following values gets written:
PROC_ASLR_FORCE_ENABLEPROC_ASLR_FORCE_DISABLEPROC_ASLR_NOFORCE
and the little detail iyk: if the currently executed image in the process itself has ASLR enabled, the PROC_ASLR_ACTIVE flag is or-ed with the value listed above. so you might get both, bestie. π
π‘οΈ PROC_SPROTECT π‘οΈ
sets the process protection state. this one is used to mark a process as protected from being killed if the system exhausts the available memory and swap β literally the bodyguard of processes, no cap. πͺ
the data parameter must point to an integer containing an operation and zero or more optional flags. the operations she supports:
PPROT_SETβ mark the selected processes as protected. π«ΆPPROT_CLEARβ clear the protected state of selected processes. π
and these are the optional flags:
PPROT_DESCENDβ apply the requested operation to all child processes of each selected process, in addition to each selected process. the nepo babies get included. πPPROT_INHERITβ when used withPPROT_SET, mark all future child processes of each selected process as protected. and those future child processes will also mark all of their future child processes. it's generational protection, she's passing it down. π§¬
π PROC_REAP_ACQUIRE π
acquires the reaper status for the current process. reaper status means that children orphaned by the reaper's descendants β that were forked after the acquisition of reaper status β get reparented to the reaper process. after system initialization, init(8) is the default reaper. so yeah, init was doing this the whole time. iconic behavior. π
πΈ PROC_REAP_RELEASE πΈ
releases the reaper state for the current process. the reaper of the current process then becomes the new reaper of the current process's descendants. passing the crown. π
π PROC_REAP_STATUS π
gives you info about the reaper of the specified process β or about the process itself when it is a reaper. the data argument must point to a procctl_reaper_status structure, which gets filled in by the syscall on successful return:
struct procctl_reaper_status {
u_int rs_flags;
u_int rs_children;
u_int rs_descendants;
pid_t rs_reaper;
pid_t rs_pid;
};
the rs_flags may have these flags returned:
REAPER_STATUS_OWNEDβ the specified process has acquired reaper status and has not released it. when this flag is returned, the specified process id,pid, identifies the reaper. otherwise thers_reaperfield of the structure is set to the pid of the reaper for the specified process id.REAPER_STATUS_REALINITβ the specified process is the root of the reaper tree, i.e.,init(8). the literal final boss. π
now the fields, bestie, pay attention:
- the
rs_childrenfield returns the number of children of the reaper among the descendants. it's possible to have a child whose reaper is not the specified process, since the reaper for any existing children is not reset on thePROC_REAP_ACQUIREoperation. so don't @ her about it. π - the
rs_descendantsfield returns the total number of descendants of the reaper(s), not counting descendants of the reaper in the subtree. - the
rs_reaperfield returns the reaper pid. - the
rs_pidreturns the pid of one reaper child, if there are any descendants.
π PROC_REAP_GETPIDS π
queries the list of descendants of the reaper of the specified process. this request takes a pointer to a procctl_reaper_pids structure in the data parameter:
struct procctl_reaper_pids {
u_int rp_count;
struct procctl_reaper_pidinfo *rp_pids;
};
when called, the rp_pids field must point to an array of procctl_reaper_pidinfo structures, to be filled in on return, and the rp_count field must specify the size of the array β the kernel will fill in no more than rp_count elements into it. no overflow, we behave. β¨
the struct procctl_reaper_pidinfo structure provides some info about one of the reaper's descendants. and okay, important caveat bestie: for a descendant that is not a child, it may be incorrectly identified because of a race in which the original child process exited and the exited process's pid was reused for an unrelated process. so like, drama. π
struct procctl_reaper_pidinfo {
pid_t pi_pid;
pid_t pi_subtree;
u_int pi_flags;
};
- the
pi_pidfield is the process id of the descendant. - the
pi_subtreefield provides the pid of the child of the reaper, which is the (grand-)parent of the process. - the
pi_flagsfield returns the following flags, further describing the descendant:REAPER_PIDINFO_VALIDβ set to indicate that theprocctl_reaper_pidinfostructure was filled in by the kernel. zero-filling therp_pidsarray and testing theREAPER_PIDINFO_VALIDflag lets the caller detect the end of the returned array. cute little sentinel, we stan. π«ΆREAPER_PIDINFO_CHILDβ thepi_pidfield identifies the direct child of the reaper.REAPER_PIDINFO_REAPERβ the reported process is itself a reaper. the descendants of the subordinate reaper are not reported. sorry bestie, they're not on the list. π
π₯ PROC_REAP_KILL π₯
request to deliver a signal to some subset of the descendants of the reaper. the data parameter must point to a procctl_reaper_kill structure, which is used both for parameters and status return.
struct procctl_reaper_kill {
int rk_sig;
u_int rk_flags;
pid_t rk_subtree;
u_int rk_killed;
pid_t rk_fpid;
};
ok so rk_sig is literally just the signal you wanna send π bestie, heads up: zero is NOT a valid signal number here, which is not how kill(2) does it, so don't get cute with it. And rk_flags is what actually steers the whole operation β you or together any of these lil guys:
REAPER_KILL_CHILDRENβ send the signal to the reaper's direct children only, nobody deeper. keep it in the family β¨REAPER_KILL_SUBTREEβ send it only to descendants that were forked by the direct child whose pid you dropped in therk_subtreefield. like, one specific branch of the tree π
And if you specify neither REAPER_KILL_CHILDREN nor REAPER_KILL_SUBTREE? then babes, it's everyone β all current descendants of the reaper get signalled. full send π
If a signal actually landed on any process, the request returns zero. in that case rk_killed tells you how many processes got signalled π and rk_fpid gets set to the pid of the first process where signal delivery failed β like, say, permission problems being rude π if there's no such process at all, rk_fpid is set to -1.
π
PROC_TRACE_CTL π
Turn tracing on or off for the specified process(es), based on whatever integer you passed in. and bestie, "tracing" here is a big umbrella β it covers attaching to the process with ptrace(2) and ktrace(2), debugging sysctls, hwpmc(4), dtrace(1), and core dumping. so many vibes, one switch π«Ά
Your possible values for the data argument:
PROC_TRACE_CTL_ENABLEβ turns tracing back on, after it got disabled byPROC_TRACE_CTL_DISABLE. only allowed for self, no doing this for other people's processes βPROC_TRACE_CTL_DISABLEβ disables tracing for the specified process. lowkey important: tracing gets re-enabled when the process changes the executing program with theexecve(2)syscall. and a child inherits the trace settings from the parent onfork(2)πΆPROC_TRACE_CTL_DISABLE_EXECβ same asPROC_TRACE_CTL_DISABLE, but the setting persists for the process even afterexecve(2). stubborn. iconic. π
π PROC_TRACE_STATUS π
Hands you the current tracing status of the specified process in the integer variable that data points to. here's the decoder ring:
- tracing disabled β data is set to
-1 - tracing enabled but no debugger attached via the
ptrace(2)syscall β data is set to0 - a debugger IS attached β data is set to the pid of the debugger process π
πͺ€ PROC_TRAPCAP_CTL πͺ€
Controls the capability mode sandbox actions for the specified sandboxed processes β specifically on a return from any syscall that gives either an ENOTCAPABLE or ECAPMODE error. if the control is enabled, those errors cause delivery of the synchronous SIGTRAP signal to the thread immediately before returning from the syscalls. caught in 4k πΈ
Your possible values for the data argument:
PROC_TRAPCAP_CTL_ENABLEβ enable theSIGTRAPsignal delivery on capability mode access violations. this enabled mode is inherited by the children of the process, and is kept afterfexecve(2)calls β¨PROC_TRAPCAP_CTL_DISABLEβ disable the signal delivery on capability mode access violations. β οΈ but note: the global sysctlkern.trap_enotcapmight still cause the signal to be delivered anyway. seecapsicum(4).
On signal delivery, the si_errno member of the siginfo signal handler parameter is set to the syscall error value, and the si_code member is set to TRAP_CAP. π―
See capsicum(4) for more info about capability mode, iykyk.
π PROC_TRAPCAP_STATUS π
Returns the current status of signalling capability mode access violations for the specified process. the integer value pointed to by the data argument gets set to PROC_TRAPCAP_CTL_ENABLE if the process control enables signal delivery, and to PROC_TRAPCAP_CTL_DISABLE otherwise.
And fr, see the note about the sysctl kern.trap_enotcap up above β that thing gives independent global control of signal delivery, so it's not just you calling the shots here π
π» PROC_PDEATHSIG_CTL π»
Requests the delivery of a signal when the parent of the calling process exits π abandonment arc. idtype must be P_PID, and id must be either the caller's pid or zero β with no difference in effect, so don't stress about which one. The value is cleared for child processes and when executing set-user-ID or set-group-ID binaries (yes, security said no). arg must point to a value of type int indicating the signal that should be delivered to the caller. use zero to cancel a previously requested signal delivery π«
π΅οΈ PROC_PDEATHSIG_STATUS π΅οΈ
Queries the current signal number that will be delivered when the parent of the calling process exits. idtype must be P_PID and id must be either the caller's pid or zero, again with no difference in effect. arg must point to a memory location that can hold a value of type int. if signal delivery has not been requested, it will contain zero on return π«§
π§ PROC_STACKGAP_CTL π§
Controls the stack gaps in the specified process. ok so what even is a stack gap? it's the part of the growth area for a MAP_STACK mapped region that's reserved and never filled by memory. instead, the process is guaranteed to receive a SIGSEGV signal on accessing pages in the gap π₯ and why do we care? because gaps protect against stack overflow corrupting memory adjacent to the stack. little bodyguard, no cap π‘οΈ
The data argument must point to an integer variable containing flags. these are the allowed ones:
PROC_STACKGAP_ENABLEβ this flag is only accepted for consistency withPROC_STACKGAP_STATUS. if stack gaps are already enabled, the flag is ignored. if they're disabled, the flag causes anEINVALerror to be returned π€ and heads up: after gaps are disabled in a process, they can only be re-enabled when anexecve(2)is performed.PROC_STACKGAP_DISABLEβ disable stack gaps for the process. for existing stacks, the gap is no longer a reserved part of the growth area and can be filled by memory on access πPROC_STACKGAP_ENABLE_EXECβ enable stack gaps for programs started after anexecve(2)by the specified process β¨PROC_STACKGAP_DISABLE_EXECβ ok so this one makes the process inherit the "stack gaps disabled" state afterexecve(2). Translation: if the program running right now has stack gaps turned off, they stay off through the exec. And if gaps were on? They stay on after exec. No surprise flips, bestie. π
The stack gap state is inherited from the parent on fork(2). Like, it's a family thing, it runs in the genes. π§¬
πΈ PROC_STACKGAP_STATUS πΈ
This one hands you back the current stack gap state for whatever process you're pointing at. data has to point to an integer variable, and that variable gets used to return a bitmask made out of these flags:
PROC_STACKGAP_ENABLEβ stack gaps are enabled, we love that for them.PROC_STACKGAP_DISABLEβ stack gaps are disabled.PROC_STACKGAP_ENABLE_EXECβ stack gaps are enabled in the process afterexecve(2).PROC_STACKGAP_DISABLE_EXECβ stack gaps are disabled in the process afterexecve(2).
π» x86 MACHINE-SPECIFIC REQUESTS π»
Heads up bestie: this whole section is the x86-only corner of the party.
π‘οΈ PROC_KPTI_CTL
AMD64 only. This controls the Kernel Page Table Isolation (KPTI) option for the children of the process you specified. For the command to actually work, the vm.pmap.kpti tunable has to be enabled on boot. And nope, you cannot change the KPTI setting for a process that's already running β the only moment you get to touch it is at execve(2), where the address space gets reinitialized. That's the one window. πͺ
The data parameter must point to an integer variable containing one of these commands:
PROC_KPTI_CTL_ENABLE_ON_EXECβ enable KPTI afterexecve(2).PROC_KPTI_CTL_DISABLE_ON_EXECβ disable KPTI afterexecve(2). Only root, or a process holding thePRIV_IOprivilege, might use this option. So like, check your privileges before you vibe-check this one.
π PROC_KPTI_STATUS
Returns the current KPTI status for the process you're asking about. data must point to the integer variable, and it returns one of these statuses:
PROC_KPTI_CTL_ENABLE_ON_EXECPROC_KPTI_CTL_DISABLE_ON_EXEC
And the status gets or-ed with PROC_KPTI_STATUS_ACTIVE in case KPTI is active for the current address space of the process. β¨
π NOTES
Okay so real talk, no cap: disabling tracing on a process should not be considered a security feature. It's bypassable β by the kernel, by privileged processes, and through other system mechanisms too. So please don't use it to reliably protect cryptographic keying material or any other confidential data. It's giving decorative, not defensive. π«π
β©οΈ RETURN VALUES
If something goes wrong, a value of -1 is returned and errno is set to indicate the error. That's it, that's the whole return story. π
π ERRORS
The procctl() system call will fail if:
- [EFAULT] β the
argparameter points outside the process's allocated address space. - [EINVAL] β the
cmdargument specifies an unsupported command. - [EINVAL] β the
idtypeargument specifies an unsupported identifier type. - [EPERM] β the calling process does not have permission to perform the requested operation on any of the selected processes.
- [ESRCH] β no processes matched the requested
idtypeandid. - [EINVAL] β an invalid operation or flag was passed in
argfor aPROC_SPROTECTcommand. - [EPERM] β the
idtypeargument is not equal toP_PID, oridis not equal to the pid of the calling process, forPROC_REAP_ACQUIREorPROC_REAP_RELEASErequests. - [EINVAL] β invalid or undefined flags were passed to a
PROC_REAP_KILLrequest. - [EINVAL] β an invalid or zero signal number was requested for a
PROC_REAP_KILLrequest. - [EINVAL] β the
PROC_REAP_RELEASErequest was issued by theinit(8)process. (sir, not you.) - [EBUSY] β the
PROC_REAP_ACQUIRErequest was issued by a process that had already acquired reaper status and has not yet released it. - [EBUSY] β the
PROC_TRACE_CTLrequest was issued for a process already being traced. - [EPERM] β the
PROC_TRACE_CTLrequest to re-enable tracing of the process (PROC_TRACE_CTL_ENABLE), or to disable persistence ofPROC_TRACE_CTL_DISABLEonexecve(2), was issued for a non-current process. - [EINVAL] β the value of the integer
dataparameter for thePROC_TRACE_CTLorPROC_TRAPCAP_CTLrequest is invalid. - [EINVAL] β the
PROC_PDEATHSIG_CTLorPROC_PDEATHSIG_STATUSrequest referenced an unsupportedid,idtypeor invalid signal number.
π SEE ALSO
dtrace(1), cap_enter(2), kill(2), ktrace(2), ptrace(2), wait(2), capsicum(4), hwpmc(4), init(8)
Go read those next, they're the rest of the friend group. π«Ά
π HISTORY
The procctl() function appeared in FreeBSD 10.0. The reaper facility is based on a similar feature of Linux and DragonflyBSD, and first appeared in FreeBSD 10.2. The PROC_PDEATHSIG_CTL facility is based on the prctl(PR_SET_PDEATHSIG, ...) feature of Linux, and first appeared in FreeBSD 11.2. And the ASLR support was added to system for the checklists compliance in FreeBSD 13.0. Glow up after glow up. π
And that's the whole page bestie!! π This version came from the Debian package, dated June 13, 2020, and it's the man page for PROCCTL(2). tysm for reading the entire thing, you're literally the main character of this terminal. mwah ππ
β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2013 Hudson River Trading LLC
- Copyright (c) 2014 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms