1.\" $OpenBSD: kthread.9,v 1.8 2007/05/31 19:20:00 jmc 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 $Mdocdate: May 31 2007 $ 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 RETURN VALUES 83Upon successful completion, 84.Fn kthread_create 85returns 0. 86Otherwise, the following error values are returned: 87.Bl -tag -width [EAGAIN] 88.It Bq Er EAGAIN 89The limit on the total number of system processes would be exceeded. 90.El 91.Sh SEE ALSO 92.Xr fork1 9 93.Sh BUGS 94There is currently no way to use 95.Va ecode 96to any sensible purpose from 97.Fn kthread_exit . 98