KPROC(9)
π KPROC(9) π β the kernel process girlies manual (Kernel Developer's Manual, bestie)
okay so welcome to the kernel process page, this is from the Kernel Developer's Manual and it's literally about kproc_start, kproc_shutdown, kproc_create, kproc_exit, kproc_resume, kproc_suspend, and kproc_suspend_check. sit down, hydrate, let's get into it π
β¨ NAME β¨
kproc_start, kproc_shutdown, kproc_create, kproc_exit, kproc_resume, kproc_suspend, kproc_suspend_check β kernel processes π«Ά
β¨ SYNOPSIS β¨
#include <sys/kthread.h>
void
kproc_start(const void *udata);
void
kproc_shutdown(void *arg, int howto);
int
kproc_create(void (*func)(void *), void *arg, struct proc **newpp,
int flags, int pages, const char *fmt, ...);
void
kproc_exit(int ecode);
int
kproc_resume(struct proc *p);
int
kproc_suspend(struct proc *p, int timo);
void
kproc_suspend_check(struct proc *p);
int
kproc_kthread_add(void (*func)(void *), void *arg,
struct proc **procptr, struct thread **tdptr, int flags, int pages,
char * procname, const char *fmt, ...);
π DESCRIPTION π
so plot twist: back in FreeBSD 8.0 the kthread*(9) family of functions got renamed to the kproc*(9) family, because bestie they were misnamed β they were actually producing kernel processes the whole time, not threads π. a whole new family of different kthread_*(9) functions got added to produce real kernel threads. go read the kthread(9) man page for the tea on those calls. also note that kproc_kthread_add(9) shows up on both pages because its functionality is split, iconic behaviour tbh.
π§ kproc_start() π§
the kproc_start() function is used to start "internal" daemons such as bufdaemon, pagedaemon, vmdaemon, and the syncer, and it is intended to be called from SYSINIT(9). the udata argument is actually a pointer to a struct kproc_desc which describes the kernel process that should be created:
struct kproc_desc {
char *arg0;
void (*func)(void);
struct proc **global_procpp;
};
the structure members get used by kproc_start() like this:
arg0β the string to be used for the name of the process. this string will be copied into thep_commmember of the new process'struct proc.funcβ the main function for this kernel process to run.global_procppβ a pointer to astruct procpointer that should be updated to point to the newly created process' process structure. if this variable isNULL, then it is ignored.
πΈ kproc_create() πΈ
the kproc_create() function is used to create a kernel process. the new process shares its address space with process 0, the swapper process, and runs in kernel mode only. the func argument specifies the function that the process should execute. the arg argument is an arbitrary pointer that is passed in as the only argument to func when it is called by the new process. the newpp pointer points to a struct proc pointer that is to be updated to point to the newly created process. if this argument is NULL, then it is ignored. the flags argument specifies a set of flags as described in rfork(2). the pages argument specifies the size of the new kernel process's stack in pages β if 0 is used, the default kernel stack size is allocated. the rest of the arguments form a printf(9) argument list that is used to build the name of the new process and is stored in the p_comm member of the new process's struct proc.
π kproc_exit() π
the kproc_exit() function is used to terminate kernel processes. it should be called by the main function of the kernel process rather than letting the main function return to its caller (pls, don't just walk out the group chat). the ecode argument specifies the exit status of the process. while exiting, the function exit1(9) will initiate a call to wakeup(9) on the process handle.
π suspend & resume squad π
the kproc_resume(), kproc_suspend(), and kproc_suspend_check() functions are used to suspend and resume a kernel process. during the main loop of its execution, a kernel process that wishes to allow itself to be suspended should call kproc_suspend_check() passing in curproc as the only argument. this function checks to see if the kernel process has been asked to suspend. if it has, it will tsleep(9) until it is told to resume. once it has been told to resume it will return, allowing execution of the kernel process to continue. the other two functions are used to notify a kernel process of a suspend or resume request. the p argument points to the struct proc of the kernel process to suspend or resume. for kproc_suspend(), the timo argument specifies a timeout to wait for the kernel process to acknowledge the suspend request and suspend itself.
π kproc_shutdown() π
the kproc_shutdown() function is meant to be registered as a shutdown event for kernel processes that need to be suspended voluntarily during system shutdown so as not to interfere with system shutdown activities. the actual suspension of the kernel process is done with kproc_suspend().
π kproc_kthread_add() π
the kproc_kthread_add() function is much like the kproc_create() function above, except that if the kproc already exists, then only a new thread (see kthread(9)) is created on the existing process. the func argument specifies the function that the process should execute. the arg argument is an arbitrary pointer that is passed in as the only argument to func when it is called by the new process. the procptr pointer points to a struct proc pointer that is the location to be updated with the new proc pointer if a new process is created, or if not NULL, must contain the process pointer for the already existing process. if this argument points to NULL, then a new process is created and the field updated. if not NULL, the tdptr pointer points to a struct thread pointer that is the location to be updated with the new thread pointer. the flags argument specifies a set of flags as described in rfork(2). the pages argument specifies the size of the new kernel thread's stack in pages β if 0 is used, the default kernel stack size is allocated. the procname argument is the name the new process should be given if it needs to be created. it is NOT a printf style format specifier but a simple string, no cap. the rest of the arguments form a printf(9) argument list that is used to build the name of the new thread and is stored in the td_name member of the new thread's struct thread.
π«Ά RETURN VALUES π«Ά
the kproc_create(), kproc_resume(), and kproc_suspend() functions return zero on success and non-zero on failure. periodt.
β EXAMPLES β
this example demonstrates the use of a struct kproc_desc and the functions kproc_start(), kproc_shutdown(), and kproc_suspend_check() to run the bufdaemon process. slay.
static struct proc *bufdaemonproc;
static struct kproc_desc buf_kp = {
"bufdaemon",
buf_daemon,
&bufdaemonproc
};
SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start,
&buf_kp)
static void
buf_daemon()
{
...
/*
* This process needs to be suspended prior to shutdown sync.
*/
EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown,
bufdaemonproc, SHUTDOWN_PRI_LAST);
...
for (;;) {
kproc_suspend_check(bufdaemonproc);
...
}
}
π ERRORS π
the kproc_resume() and kproc_suspend() functions will fail if:
[EINVAL]β thepargument does not reference a kernel process. (like, who even is she π)
the kproc_create() function will fail if:
[EAGAIN]β the system-imposed limit on the total number of processes under execution would be exceeded. the limit is given by thesysctl(3)MIB variableKERN_MAXPROC.[EINVAL]β theRFCFDGflag was specified in theflagsparameter.
π SEE ALSO π
rfork(2), exit1(9), kthread(9), SYSINIT(9), wakeup(9)
π¦ HISTORY π¦
the kproc_start() function first appeared in FreeBSD 2.2. the kproc_shutdown(), kproc_create(), kproc_exit(), kproc_resume(), kproc_suspend(), and kproc_suspend_check() functions were introduced in FreeBSD 4.0. prior to FreeBSD 5.0, the kproc_shutdown(), kproc_resume(), kproc_suspend(), and kproc_suspend_check() functions were named shutdown_kproc(), resume_kproc(), shutdown_kproc(), and kproc_suspend_loop(), respectively. originally they had the names kthread_*() but were changed to kproc_*() when real kthreads became available. glow-up fr fr β¨
aaaand that's the whole page bestie π«Ά this one's from the Debian build of the page, dated October 19, 2007. go forth and suspend your kernel processes responsibly, 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) 2000-2001 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms