xref: /openbsd-src/share/man/man9/kthread.9 (revision 2d25794915b1a72ef7ffbd4e4ff3fd6fe3543962)
1*2d257949Sderaadt.\"	$OpenBSD: kthread.9,v 1.10 2013/11/18 20:21:50 deraadt Exp $
20b4b4641Sespie.\"
30b4b4641Sespie.\" Copyright (c) 1999 Marc Espie
40b4b4641Sespie.\" All rights reserved.
50b4b4641Sespie.\"
60b4b4641Sespie.\" Redistribution and use in source and binary forms, with or without
70b4b4641Sespie.\" modification, are permitted provided that the following conditions
80b4b4641Sespie.\" are met:
90b4b4641Sespie.\" 1. Redistributions of source code must retain the above copyright
100b4b4641Sespie.\"    notice, this list of conditions and the following disclaimer.
110b4b4641Sespie.\" 2. Redistributions in binary form must reproduce the above copyright
120b4b4641Sespie.\"    notice, this list of conditions and the following disclaimer in the
130b4b4641Sespie.\"    documentation and/or other materials provided with the distribution.
140b4b4641Sespie.\"
150b4b4641Sespie.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
160b4b4641Sespie.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
170b4b4641Sespie.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
180b4b4641Sespie.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
190b4b4641Sespie.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
200b4b4641Sespie.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
210b4b4641Sespie.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
220b4b4641Sespie.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
230b4b4641Sespie.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
240b4b4641Sespie.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
250b4b4641Sespie.\"
26*2d257949Sderaadt.Dd $Mdocdate: November 18 2013 $
270b4b4641Sespie.Dt KTHREAD 9
280b4b4641Sespie.Os
290b4b4641Sespie.Sh NAME
300b4b4641Sespie.Nm kthread_create ,
310b4b4641Sespie.Nm kthread_exit ,
320b4b4641Sespie.Nm kthread_create_deferred
33ca8c6f66Sdavid.Nd kernel threads
340b4b4641Sespie.Sh SYNOPSIS
35dddd2645Sschwarze.In sys/kthread.h
360b4b4641Sespie.Ft int
37*2d257949Sderaadt.Fn kthread_create "void (*func)(void *)" "void *arg" "struct proc **newpp" "const char *name"
380b4b4641Sespie.Ft void
390b4b4641Sespie.Fn kthread_exit "int ecode"
400b4b4641Sespie.Ft void
41c4ed614fSjmc.Fn kthread_create_deferred "void (*func)(void *)" "void *arg"
420b4b4641Sespie.Sh DESCRIPTION
430b4b4641SespieKernel threads are system light-weight processes: cloned from process 0
440b4b4641Sespie(the swapper), sharing its memory map and limits, but with a copy of its
45ab967380Saaronfile descriptor table.
46ab967380SaaronThey don't receive broadcast nor group signals and they can't be swapped.
470b4b4641Sespie.Pp
480b4b4641SespieAny process can call
490b4b4641Sespie.Fn kthread_create
50ab967380Saaronto create a kernel thread.
51ab967380SaaronThe new process starts up executing
520b4b4641Sespie.Fa func
530b4b4641Sespiewith argument
540b4b4641Sespie.Fa arg .
550b4b4641SespieIf
560b4b4641Sespie.Fa newpp
578b3caad3Sespieis not
588b3caad3Sespie.Dv NULL ,
598b3caad3Sespieit is filled with the address of the new process.
60*2d257949Sderaadt.Fa name
61*2d257949Sderaadtis used to name the process.
620b4b4641Sespie.Pp
630b4b4641SespieA kernel thread will terminate by calling
640b4b4641Sespie.Fn kthread_exit ,
650b4b4641Sespiewith exit code
660b4b4641Sespie.Fa ecode .
670b4b4641Sespie.Pp
680b4b4641SespieSince the system has to be up and running for creating
690b4b4641Sespienew processes, device drivers that want to create kernel threads early
70ab967380Saaron(e.g., at attach time) may use
710b4b4641Sespie.Fn kthread_create_deferred
72ab967380Saaroninstead.
73ab967380SaaronThe system will call back the function
740b4b4641Sespie.Fa func
750b4b4641Sespiewith argument
760b4b4641Sespie.Fa arg
770b4b4641Sespiewhen it can create threads, so it is up to
780b4b4641Sespie.Fa func
790b4b4641Sespieto call
800b4b4641Sespie.Fn kthread_create
810b4b4641Sespieat that point.
82849b92c5Sgrange.Sh RETURN VALUES
83849b92c5SgrangeUpon successful completion,
84849b92c5Sgrange.Fn kthread_create
85849b92c5Sgrangereturns 0.
86849b92c5SgrangeOtherwise, the following error values are returned:
87849b92c5Sgrange.Bl -tag -width [EAGAIN]
88849b92c5Sgrange.It Bq Er EAGAIN
89849b92c5SgrangeThe limit on the total number of system processes would be exceeded.
90849b92c5Sgrange.El
910b4b4641Sespie.Sh SEE ALSO
920b4b4641Sespie.Xr fork1 9
930b4b4641Sespie.Sh BUGS
940b4b4641SespieThere is currently no way to use
950b4b4641Sespie.Va ecode
960b4b4641Sespieto any sensible purpose from
970b4b4641Sespie.Fn kthread_exit .
98