Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

cpu_lwp_fork(9) [netbsd man page]

CPU_LWP_FORK(9) 					   BSD Kernel Developer's Manual					   CPU_LWP_FORK(9)

cpu_lwp_fork, child_return, proc_trampoline -- finish a fork operation SYNOPSIS
#include <sys/proc.h> void cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize, void (*func)(void *), void *arg); void child_return(void *arg); DESCRIPTION
cpu_lwp_fork() is the machine-dependent portion of fork1() which finishes a fork operation, with child lwp l2 nearly set up. It copies and updates the PCB and trap frame from the parent l1, making the child ready to run. cpu_lwp_fork() rigs the child's kernel stack so that it will start in proc_trampoline(). proc_trampoline() does not have a normal calling sequence and is entered by cpu_switch(). If an alternate user-level stack is requested (with non-zero values in both the stack and stacksize arguments), the user stack pointer is set up accordingly. After being entered by cpu_switch() and while running in user context (within the kernel) proc_trampoline() will invoke the function func with the argument arg. If a kernel thread is being created, the return path and argument are specified with func and arg. If a user process is being created, fork1() will pass child_return() and l2 to cpu_lwp_fork() as func and arg respectively. This causes the newly-created child process to go directly to user level with an apparent return value of 0 from fork(2), while the parent process returns normally. SEE ALSO
fork(2), cpu_switchto(9), fork1(9) BSD
April 13, 2010 BSD

Check Out this Related Man Page

RFORK_THREAD(3) 					   BSD Library Functions Manual 					   RFORK_THREAD(3)

rfork_thread -- create a rfork-based process thread LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> pid_t rfork_thread(int flags, void *stack, int (*func)(void *arg), void *arg); DESCRIPTION
The rfork_thread() function has been deprecated in favor of pthread_create(3). The rfork_thread() function is a helper function for rfork(2). It arranges for a new process to be created and the child process will call the specified function with the specified argument, while running on the supplied stack. Using this function should avoid the need to implement complex stack swap code. RETURN VALUES
Upon successful completion, rfork_thread() returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable errno is set to indicate the error. The child process context is not aware of a return from the rfork_thread() function as it begins executing directly with the supplied func- tion. ERRORS
See rfork(2) for error return codes. SEE ALSO
fork(2), intro(2), minherit(2), rfork(2), vfork(2), pthread_create(3) HISTORY
The rfork_thread() function first appeared in FreeBSD 4.3. BSD
February 6, 2011 BSD
Man Page