Blame


1 058b0118 2005-01-03 devnull .TH RFORK 3
2 058b0118 2005-01-03 devnull .SH NAME
3 058b0118 2005-01-03 devnull rfork \- manipulate process state
4 058b0118 2005-01-03 devnull .SH SYNOPSIS
5 058b0118 2005-01-03 devnull .B #include <u.h>
6 058b0118 2005-01-03 devnull .br
7 058b0118 2005-01-03 devnull .B #include <libc.h>
8 058b0118 2005-01-03 devnull .PP
9 058b0118 2005-01-03 devnull .nf
10 058b0118 2005-01-03 devnull .B
11 058b0118 2005-01-03 devnull int rfork(int flags)
12 058b0118 2005-01-03 devnull .fi
13 058b0118 2005-01-03 devnull .SH DESCRIPTION
14 058b0118 2005-01-03 devnull .I Rfork
15 058b0118 2005-01-03 devnull is a partial implementation of the Plan 9 system call.
16 058b0118 2005-01-03 devnull It can be used to manipulate some process state and to create
17 058b0118 2005-01-03 devnull new processes a la
18 d32deab1 2020-08-16 rsc .MR fork (2) .
19 058b0118 2005-01-03 devnull It cannot be used to create shared-memory processes
20 058b0118 2005-01-03 devnull (Plan 9's
21 058b0118 2005-01-03 devnull .B RFMEM
22 058b0118 2005-01-03 devnull flag); for that functionality use
23 058b0118 2005-01-03 devnull .I proccreate
24 058b0118 2005-01-03 devnull (see
25 d32deab1 2020-08-16 rsc .MR thread (3) ).
26 058b0118 2005-01-03 devnull .PP
27 058b0118 2005-01-03 devnull The
28 058b0118 2005-01-03 devnull .I flags
29 058b0118 2005-01-03 devnull argument to
30 058b0118 2005-01-03 devnull .I rfork
31 058b0118 2005-01-03 devnull selects which resources of the
32 058b0118 2005-01-03 devnull invoking process (parent) are shared
33 058b0118 2005-01-03 devnull by the new process (child) or initialized to
34 058b0118 2005-01-03 devnull their default values.
35 058b0118 2005-01-03 devnull .I Flags
36 058b0118 2005-01-03 devnull is the logical OR of some subset of
37 058b0118 2005-01-03 devnull .TF RFCNAMEG
38 058b0118 2005-01-03 devnull .TP
39 058b0118 2005-01-03 devnull .B RFPROC
40 058b0118 2005-01-03 devnull If set a new process is created; otherwise changes affect the
41 058b0118 2005-01-03 devnull current process.
42 058b0118 2005-01-03 devnull .TP
43 058b0118 2005-01-03 devnull .B RFNOWAIT
44 058b0118 2005-01-03 devnull If set, the child process will be dissociated from the parent. Upon
45 058b0118 2005-01-03 devnull exit the child will leave no
46 058b0118 2005-01-03 devnull .B Waitmsg
47 058b0118 2005-01-03 devnull (see
48 d32deab1 2020-08-16 rsc .MR wait (3) )
49 058b0118 2005-01-03 devnull for the parent to collect.
50 058b0118 2005-01-03 devnull .\" .TP
51 058b0118 2005-01-03 devnull .\" .B RFNAMEG
52 058b0118 2005-01-03 devnull .\" If set, the new process inherits a copy of the parent's name space;
53 058b0118 2005-01-03 devnull .\" otherwise the new process shares the parent's name space.
54 058b0118 2005-01-03 devnull .\" Is mutually exclusive with
55 058b0118 2005-01-03 devnull .\" .BR RFCNAMEG .
56 058b0118 2005-01-03 devnull .\" .TP
57 058b0118 2005-01-03 devnull .\" .B RFCNAMEG
58 058b0118 2005-01-03 devnull .\" If set, the new process starts with a clean name space. A new
59 058b0118 2005-01-03 devnull .\" name space must be built from a mount of an open file descriptor.
60 058b0118 2005-01-03 devnull .\" Is mutually exclusive with
61 058b0118 2005-01-03 devnull .\" .BR RFNAMEG .
62 058b0118 2005-01-03 devnull .\" .TP
63 058b0118 2005-01-03 devnull .\" .B RFNOMNT
64 058b0118 2005-01-03 devnull .\" If set, subsequent mounts into the new name space and dereferencing
65 058b0118 2005-01-03 devnull .\" of pathnames starting with
66 058b0118 2005-01-03 devnull .\" .B #
67 058b0118 2005-01-03 devnull .\" are disallowed.
68 058b0118 2005-01-03 devnull .\" .TP
69 058b0118 2005-01-03 devnull .\" .B RFENVG
70 058b0118 2005-01-03 devnull .\" If set, the environment variables are copied;
71 058b0118 2005-01-03 devnull .\" otherwise the two processes share environment variables.
72 058b0118 2005-01-03 devnull .\" Is mutually exclusive with
73 058b0118 2005-01-03 devnull .\" .BR RFCENVG .
74 058b0118 2005-01-03 devnull .\" .TP
75 058b0118 2005-01-03 devnull .\" .B RFCENVG
76 058b0118 2005-01-03 devnull .\" If set, the new process starts with an empty environment.
77 058b0118 2005-01-03 devnull .\" Is mutually exclusive with
78 058b0118 2005-01-03 devnull .\" .BR RFENVG .
79 058b0118 2005-01-03 devnull .TP
80 058b0118 2005-01-03 devnull .B RFNOTEG
81 058b0118 2005-01-03 devnull Each process is a member of a group of processes that all
82 058b0118 2005-01-03 devnull receive notes when a note is sent to the group
83 058b0118 2005-01-03 devnull (see
84 d32deab1 2020-08-16 rsc .MR postnote (3)
85 058b0118 2005-01-03 devnull and
86 d32deab1 2020-08-16 rsc .MR signal (2) ).
87 058b0118 2005-01-03 devnull The group of a new process is by default the same as its parent, but if
88 058b0118 2005-01-03 devnull .B RFNOTEG
89 058b0118 2005-01-03 devnull is set (regardless of
90 058b0118 2005-01-03 devnull .BR RFPROC ),
91 058b0118 2005-01-03 devnull the process becomes the first in a new group, isolated from
92 058b0118 2005-01-03 devnull previous processes.
93 058b0118 2005-01-03 devnull In Plan 9, a process can call
94 058b0118 2005-01-03 devnull .B rfork(RFNOTEG)
95 058b0118 2005-01-03 devnull and then be sure that it will no longer receive console interrupts
96 058b0118 2005-01-03 devnull or other notes.
97 058b0118 2005-01-03 devnull Unix job-control shells put each command in its own process group
98 058b0118 2005-01-03 devnull and then relay notes to the current foreground command, making
99 058b0118 2005-01-03 devnull the idiom less useful.
100 058b0118 2005-01-03 devnull .TP
101 058b0118 2005-01-03 devnull .B RFFDG
102 058b0118 2005-01-03 devnull If set, the invoker's file descriptor table (see
103 058b0118 2005-01-03 devnull .IR intro ( ))
104 058b0118 2005-01-03 devnull is copied; otherwise the two processes share a
105 058b0118 2005-01-03 devnull single table.
106 058b0118 2005-01-03 devnull .\" .TP
107 058b0118 2005-01-03 devnull .\" .B RFCFDG
108 058b0118 2005-01-03 devnull .\" If set, the new process starts with a clean file descriptor table.
109 058b0118 2005-01-03 devnull .\" Is mutually exclusive with
110 058b0118 2005-01-03 devnull .\" .BR RFFDG .
111 058b0118 2005-01-03 devnull .\" .TP
112 058b0118 2005-01-03 devnull .\" .B RFREND
113 058b0118 2005-01-03 devnull .\" If set, the process will be unable to
114 058b0118 2005-01-03 devnull .\" .IR rendezvous (3)
115 058b0118 2005-01-03 devnull .\" with any of its ancestors; its children will, however, be able to
116 058b0118 2005-01-03 devnull .\" .B rendezvous
117 058b0118 2005-01-03 devnull .\" with it. In effect,
118 058b0118 2005-01-03 devnull .\" .B RFREND
119 058b0118 2005-01-03 devnull .\" makes the process the first in a group of processes that share a space for
120 058b0118 2005-01-03 devnull .\" .B rendezvous
121 058b0118 2005-01-03 devnull .\" tags.
122 058b0118 2005-01-03 devnull .\" .TP
123 058b0118 2005-01-03 devnull .\" .B RFMEM
124 058b0118 2005-01-03 devnull .\" If set, the child and the parent will share
125 058b0118 2005-01-03 devnull .\" .B data
126 058b0118 2005-01-03 devnull .\" and
127 058b0118 2005-01-03 devnull .\" .B bss
128 058b0118 2005-01-03 devnull .\" segments.
129 058b0118 2005-01-03 devnull .\" Otherwise, the child inherits a copy of those segments.
130 058b0118 2005-01-03 devnull .\" Other segment types, in particular stack segments, will be unaffected.
131 058b0118 2005-01-03 devnull .\" May be set only with
132 058b0118 2005-01-03 devnull .\" .BR RFPROC .
133 058b0118 2005-01-03 devnull .PD
134 058b0118 2005-01-03 devnull .PP
135 058b0118 2005-01-03 devnull File descriptors in a shared file descriptor table are kept
136 058b0118 2005-01-03 devnull open until either they are explicitly closed
137 058b0118 2005-01-03 devnull or all processes sharing the table exit.
138 058b0118 2005-01-03 devnull .PP
139 058b0118 2005-01-03 devnull If
140 058b0118 2005-01-03 devnull .B RFPROC
141 058b0118 2005-01-03 devnull is set, the
142 058b0118 2005-01-03 devnull value returned in the parent process
143 058b0118 2005-01-03 devnull is the process id
144 058b0118 2005-01-03 devnull of the child process; the value returned in the child is zero.
145 058b0118 2005-01-03 devnull Without
146 058b0118 2005-01-03 devnull .BR RFPROC ,
147 058b0118 2005-01-03 devnull the return value is zero.
148 058b0118 2005-01-03 devnull Process ids range from 1 to the maximum integer
149 058b0118 2005-01-03 devnull .RB ( int )
150 058b0118 2005-01-03 devnull value.
151 058b0118 2005-01-03 devnull .I Rfork
152 058b0118 2005-01-03 devnull will sleep, if necessary, until required process resources are available.
153 058b0118 2005-01-03 devnull .PP
154 058b0118 2005-01-03 devnull Calling
155 058b0118 2005-01-03 devnull .B rfork(RFFDG|RFPROC)
156 058b0118 2005-01-03 devnull is equivalent to calling
157 d32deab1 2020-08-16 rsc .MR fork (2) .
158 058b0118 2005-01-03 devnull .SH SOURCE
159 c3674de4 2005-01-11 devnull .B \*9/src/lib9/rfork.c
160 058b0118 2005-01-03 devnull .SH DIAGNOSTICS
161 058b0118 2005-01-03 devnull .I Rfork
162 058b0118 2005-01-03 devnull sets
163 058b0118 2005-01-03 devnull .IR errstr .