kthread.9 revision 1.3
$NetBSD: kthread.9,v 1.3 2001/09/04 03:05:07 wiz Exp $

Copyright (c) 2000 The NetBSD Foundation, Inc.
All rights reserved.

This code is derived from software contributed to The NetBSD Foundation
by Gregory McGarry.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by the NetBSD
Foundation, Inc. and its contributors.
4. Neither the name of The NetBSD Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

.Dd July 9, 2000 .Dt KTHREAD 9 .Os .Sh NAME .Nm kthread_create1 , .Nm kthread_exit , .Nm kthread_create .Nd kernel threads .Sh SYNOPSIS .Fd #include <sys/kthread.h> .Ft void .Fn kthread_create "void (*func)(void)" "void *arg" .Ft void .Fn kthread_exit "int ecode" .Ft int .Fn kthread_create1 "void (*func)(void)" "void *arg" "struct proc **newpp" \ "const char *fmt" "..." .Sh DESCRIPTION Kernel threads are light-weight processes which execute entirely within the kernel. Any process can request the creation of a new kernel thread. Kernel threads are not swapped out during memory congestion. The VM space and limits are shaed with proc0 (usually .Xr init 8 ) . .Sh FUNCTIONS l -tag -width compact t Fn kthread_create1 "func" "arg" "newpp" "fmt" "..." Fork a kernel thread. .Fa newpp is a pointer the the new proc structure for the kernel thread. The function .Fa func is called with arguments .Fa arg to commence execution. .Fa fmt is a string containing format information used to display the kernel thread name. t Fn kthread_create "void (*func)(void)" "void *arg" Register function .Fa func to defer creation of the kernel thread. Deferral of kernel thread creation is required during system startup when kernel thread resources are not available. t Fn kthread_exit "int ecode" Exit from a kernel thread. .El .Sh RETURN VALUES Upon successful completion, .Fn kthread_create1 returns 0. Otherwise, the following error values are returned: l -tag -width [EAGAIN] t Bq Er EAGAIN The limit on the total number of system processes would be exceeded. t Bq Er EAGAIN The limit .Dv RLIMIT_NPROC on the total number of processes under execution by this user id would be exceeded. .El .Sh CODE REFERENCES This section describes places within the .Nx source tree where actual code implementing or utilising the kthread framework can be found. All pathnames are relative to

a /usr/src .

p The kthread framework itself is implemented within the file

a sys/kern/kern_kthread.c . Data structures and function prototypes for the framework are located in

a sys/sys/kthread.h . .Sh SEE ALSO .Xr driver 9 , .Xr fork1 9 .Sh HISTORY The kthread framework appeared in .Nx 1.4 .