1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX \" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS
.PD 0
.ft 5
.nf
..
.de EE \" end example
.fi
.ft
.PD
.RE
.PP
..
.TH PROC 3
.SH NAME
proc \- process control routines
.SH SYNOPSIS
.EX
#include <proc.h>
Proc_t* procopen(const char* \fIcommand\fP, char** \fIargv\fP, char** \fIenvv\fP, long* \fIopv\fP, long \fIflags\fP);
int procfree(Proc_t* \fIproc\fP);
int procclose(Proc_t* \fIproc\fP);
int procrun(const char* \fIcommand\fP, char** \fIargv\fP);
.EE
.SH DESCRIPTION
These routines provide a portable interface to process creation and execution.
They work on systems with
.IR fork (2)
and
.IR exec (2)
as well as on systems with only
.IR spawnve (2)
or
.IR spanwveg (3).
.PP
.L procopen
runs
.I command
with arguments
.IR argv ,
environment modifications in
.IR envv ,
file descriptor, signal and process group operations in
.I opv
and flags in
.IR flags .
.PP
.I command
is searched for using the
.L PATH
environment variable from the calling environment.
If
.I command
is
.L 0
then the current shell is used (see
.IR pathshell (3)).
If
.I envv
is not
.L 0
then it is a
.L 0
terminated vector of
\fIname\fP[=\fIvalue\fP]
strings that are added to the
.I command
environment using
.IR setenviron (3).
If
.I name
appears in the parent environment then its value is replaced with the new
.IR value .
If
.RI = value
is omitted then
.I name
is removed from the child environment.
The
.L _
environment variable is set to contain the pathname for
.I command
and will appear at the top of the child environment.
.PP
If
.I opv
is not
.L 0
then it is a 0 terminaled vector of operations to perform.
In the following
.I context
is a combination of
.L PROC_FD_CHILD
and
.L PROC_FD_PARENT
for the child and parent process context respectively.
Valid operations are:
.TP
\f5PROC_FD_CLOSE(\fIfd\fP,\fIcontext\fP)\fR
The file descriptor
.I fd
is closed in
.IR context .
.TP
\f5PROC_FD_DUP(\fIfrom\fP,\fIto\fP,\fIcontext\fP)\fR
The file descriptor
.I from
is
.IR dup (2)'d
into the file descriptor
.I to
in
.IR context .
.TP
\f5PROC_SIG_DFL(\fIsig\fP)\fR
The signal handler for
.I sig
is set to
.L SIG_DFL
in the child context.
.TP
\f5PROC_SIG_IGN(\fIsig\fP)\fR
The signal handler for
.I sig
is set to
.L SIG_IGN
in the child context.
.TP
\f5PROC_SYS_PGRP(\fIpgid\fP)\fR
The child process group is set to
.IR pgid .
.I pgid
may have the following values:
.TP
.L <0
The child process becomes a session leader.
.TP
.L 0
The child process is in the parent process group.
.TP
.L 1
The child process becomes a process group leader.
.TP
.L >1
The child process joins the process group
.IR pgid .
.TP
\f5PROC_SYS_UMASK(\fImask\fP)\fR
The child process group file creation mask is set to
.IR mask .
.PP
.I flags
is the inclusive-or of the following:
.TP
.L PROC_ARGMOD
.I "argv[-1]"
and
.I "argv[0]"
may be modified.
This is an optimization that avoids an environment vector
.I realloc(3)
when
.I command
is a shell script.
.TP
.L PROC_BACKGROUND
Standard shell
.L &
setup is done for the child process.
.TP
.L PROC_CLEANUP
Parent process redirection file discriptors are closed on error.
.TP
.L PROC_DAEMON
Standard daemon setup is done for the child process.
.TP
.L PROC_ENVCLEAR
The child environment is cleared before
.I envv
is added.
.TP
.L PROC_GID
The child effective group id is set to the real group id.
.TP
.L PROC_IGNORE
Parent pipe errors are ignored.
.TP
.L PROC_OVERLAY
The current process is overlayed by
.I command
if possible
(i.e., the
.IR fork (2)
call is omitted).
.TP
.L PROC_PARANOID
Paranoid:
.I command
is searched using the default standard
.LR PATH ;
the child environment variable
.L PATH
is set to the default standard;
the
.L PROC_GID
and
.L PROC_UID
modes are set;
only
.L /bin/sh
is used to execute
.I command
if it is a shell script.
.TP
.L PROC_PRIVELEGED
If the effective user id is
.L 0
then the child real user id is set to
.L 0
and the child real group id is set to the effective group id.
.TP
.L PROC_READ
.I proc.rfd
is connected to
.IR command 's
standard output.
.TP
.L PROC_SESSION
The child process becomes a session group leader.
(Equivalent to the
.I opv
entry
.LR PROC_SYS_PGRP(-1) .)
.TP
.L PROC_UID
The child effective user id is set to the real user id.
.TP
.L PROC_WRITE
.I proc.wfd
is connected to
.IR commands 's
standard input.
.PP
The return value is a pointer to a structure with the following members:
.TP
.L "pid_t \fIpid\fP"
The child process id.
.TP
.L "pid_t \fIpgrp\fP"
The child process group.
.TP
.L "int \fIrfd\fP"
A read file descriptor connected to
.IR command 's
standard output.
.TP
.L "int \fIwfd\fP"
A write file descriptor connected to
.IR command 's
standard input.
.PP
If an error occurs then
.L 0
is returned.
.PP
.L procclose
waits for the process
.I proc
to complete and then closes the command stream
.IR proc .
The command exit status is returned.
.L -1
is returned if the child portion of
.L procopen
failed.
.PP
.L procfree
frees the process stream without waiting for
.I command
to complete.
Presumably some other mechanism will be used to wait for
.IR proc.pid .
.PP
.L procrun
combines
.L procopen
and
.L procclose
with the flags
.L PROC_GID|PROC_UID
and returns the command exit status.
.SH "SEE ALSO"
popen(3), sfpopen(3), spawnveg(3), system(3)
|