*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> kthread_exit (9)              



NAME    [Toc]    [Back]

     kproc_start, kproc_shutdown, kthread_create, kthread_exit,
     kthread_resume, kthread_suspend, kthread_suspend_check -- kernel threads

SYNOPSIS    [Toc]    [Back]

     #include <sys/kthread.h>

     kproc_start(const void *udata);

     kproc_shutdown(void *arg, int howto);

     kthread_create(void (*func)(void *), void *arg, struct proc **newpp,
	 int flags, int pages, const char *fmt, ...);

     kthread_exit(int ecode);

     kthread_resume(struct proc *p);

     kthread_suspend(struct proc *p, int timo);

     kthread_suspend_check(struct proc *p);

DESCRIPTION    [Toc]    [Back]

     The function kproc_start() is used to start ``internal'' daemons such as
     bufdaemon, pagedaemon, vmdaemon, and the syncer and is intended to be
     called from SYSINIT(9).  The udata argument is actually a pointer to a
     struct kproc_desc which describes the kernel thread that should be created:

	   struct kproc_desc {
		   char 	   *arg0;
		   void 	   (*func)(void);
		   struct proc	   **global_procpp;

     The structure members are used by kproc_start() as follows:

	   arg0 	  String to be used for the name of the process.  This
			  string will be copied into the p_comm member of the
			  new process' struct proc.

	   func 	  The main function for this kernel process to run.

	   global_procpp  A pointer to a struct proc pointer that should be
			  updated to point to the newly created process'
			  process structure.  If this variable is NULL, then
			  it is ignored.

     The kthread_create() function is used to create a kernel thread.  The new
     thread shares its address space with process 0, the swapper process, and
     runs in kernel mode only.	The func argument specifies the function that
     the thread 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 thread'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 thread and is stored in
     the p_comm member of the new thread's struct proc.

     The kthread_exit() function is used to terminate kernel threads.  It
     should be called by the main function of the kernel thread rather than
     letting the main function return to its caller.  The ecode argument specifies
 the exit status of the thread.

     The kthread_resume(), kthread_suspend(), and kthread_suspend_check()
     functions are used to suspend and resume a kernel thread.	During the
     main loop of its execution, a kernel thread that wishes to allow itself
     to be suspended should call kthread_suspend_check() passing in curproc as
     the only argument.  This function checks to see if the kernel thread 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 thread to continue.  The other two functions are used
     to notify a kernel thread of a suspend or resume request.	The p argument
     points to the struct proc of the kernel thread to suspend or resume.  For
     kthread_suspend(), the timo argument specifies a timeout to wait for the
     kernel thread to acknowledge the suspend request and suspend itself.

     The kproc_shutdown() function is meant to be registered as a shutdown
     event for kernel threads that need to be suspended voluntarily during
     system shutdown so as not to interfere with system shutdown activities.
     The actual suspension of the kernel thread is done with

RETURN VALUES    [Toc]    [Back]

     The kthread_create(), kthread_resume(), and kthread_suspend() functions
     return zero on success and non-zero on failure.

EXAMPLES    [Toc]    [Back]

     This example demonstrates the use of a struct kproc_desc and the functions
 kproc_start(), kproc_shutdown(), and kthread_suspend_check() to run
     the ``bufdaemon'' process.

	   static struct proc *bufdaemonproc;

	   static struct kproc_desc buf_kp = {
	   SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start,

	   static void
		    * This process needs to be suspended prior to shutdown sync.
		   EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown,
		       bufdaemonproc, SHUTDOWN_PRI_LAST);
		   for (;;) {

ERRORS    [Toc]    [Back]

     The kthread_resume() and kthread_suspend() functions will fail if:

     [EINVAL]		The p argument does not reference a kernel thread.

     The kthread_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 the sysctl(3) MIB variable KERN_MAXPROC.

     [EINVAL]		The RFCFDG flag was specified in the flags parameter.

SEE ALSO    [Toc]    [Back]

     rfork(2), SYSINIT(9)

HISTORY    [Toc]    [Back]

     The kproc_start() function first appeared in FreeBSD 2.2.	The
     kproc_shutdown(), kthread_create(), kthread_exit(), kthread_resume(),
     kthread_suspend(), and kthread_suspend_check() functions were introduced
     in FreeBSD 4.0.  Prior to FreeBSD 5.0, the kproc_shutdown(),
     kthread_resume(), kthread_suspend(), and kthread_suspend_check() functions
 were named shutdown_kproc(), resume_kproc(), shutdown_kproc(), and
     kproc_suspend_loop(), respectively.

FreeBSD 5.2.1		       October 24, 2000 		 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
ithread_priority FreeBSD kernel interrupt threads
ithread FreeBSD kernel interrupt threads
ithread_create FreeBSD kernel interrupt threads
ithread_destroy FreeBSD kernel interrupt threads
ithread_schedule FreeBSD kernel interrupt threads
ithread_remove_handler FreeBSD kernel interrupt threads
ithread_add_handler FreeBSD kernel interrupt threads
kse_release FreeBSD kernel support for user threads
kse_exit FreeBSD kernel support for user threads
kse_create FreeBSD kernel support for user threads
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service