xref: /openbsd/share/man/man9/kthread.9 (revision db3296cf)
1.\"	$OpenBSD: kthread.9,v 1.5 2003/06/04 04:29:03 deraadt Exp $
2.\"
3.\" Copyright (c) 1999 Marc Espie
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.Dd September 1, 1999
27.Dt KTHREAD 9
28.Os
29.Sh NAME
30.Nm kthread_create ,
31.Nm kthread_exit ,
32.Nm kthread_create_deferred
33.Nd kernel threads
34.Sh SYNOPSIS
35.Fd #include <sys/kthread.h>
36.Ft int
37.Fn kthread_create "void (*func)(void)" "void *arg" "struct proc **newpp" "const char *fmt" ...
38.Ft void
39.Fn kthread_exit "int ecode"
40.Ft void
41.Fn kthread_create_deferred "void (*func)(void)" "void *arg"
42.Sh DESCRIPTION
43Kernel threads are system light-weight processes: cloned from process 0
44(the swapper), sharing its memory map and limits, but with a copy of its
45file descriptor table.
46They don't receive broadcast nor group signals and they can't be swapped.
47.Pp
48Any process can call
49.Fn kthread_create
50to create a kernel thread.
51The new process starts up executing
52.Fa func
53with argument
54.Fa arg .
55If
56.Fa newpp
57is not
58.Dv NULL ,
59it is filled with the address of the new process.
60.Fa fmt
61and the remaining arguments are used to name the process.
62.Pp
63A kernel thread will terminate by calling
64.Fn kthread_exit ,
65with exit code
66.Fa ecode .
67.Pp
68Since the system has to be up and running for creating
69new processes, device drivers that want to create kernel threads early
70(e.g., at attach time) may use
71.Fn kthread_create_deferred
72instead.
73The system will call back the function
74.Fa func
75with argument
76.Fa arg
77when it can create threads, so it is up to
78.Fa func
79to call
80.Fn kthread_create
81at that point.
82.Sh SEE ALSO
83.Xr fork1 9
84.Sh BUGS
85There is currently no way to use
86.Va ecode
87to any sensible purpose from
88.Fn kthread_exit .
89