SPAWN(2) SPAWN(2) Name spawn, die - process handling functions #include <ulib.h> typedef void (*Spawnf)(char*, char*); void spawn(char* arg0, char* args, int dup, Spawnf f, char* a) void die(char* reason) Description Spawn is a convenience function used to start a new process. It uses the proc(4) boxes to do so. The program executed by the new process is arg0 , with the command line set as passed in args . Dup is a set of bits used to control how virtual memory, name space, and program are initialized: DPROG when set, causes the program arg0 to be copied (not linked) to the new process program box. Even when DPROC is not set, the program will be copied if the link operation failsto allow callers to try link(2) and still get the process created when the program does not share the machine with the processor. DVM when set, causes the /b/proc/me/vm virtual memory box to be copied (not linked) to the new process. DNS when set, causes the /b/proc/me/ns name space to be copied (not linked) to the process. If the parameter f is nil, a is considered to be the name for a box to link to the process legacy; it may be nil. Oth- erwise, f is a function to be called before copying/linking the program, and a is an argument to be given to f . This is useful to modify the new process environment before it is allowed to run. Die is a convenience function that terminates process execu- tion. The string given is copied to the process legacy box. Example maken("/b/term/shterm", "text", nil, nil, nil); maken("/b/chan/towait"); spawn("sh", "sh", DVM, termio, term); spawn("sh", "sh", DVM, nil, "/b/chan/towait"); copy("/b/chan/towait", "/b/proc/me/io1"); The first call to spawn creates a new process to execute /bin/sh so that it runs at a different address space. The I/O boxes for the new process are set by termio , which is supposed to be a function that links I/O boxes in the new process to the argument given (that is shterm in the exam- ple). The second call to spawn creates a process using the same SPAWN(2) SPAWN(2) I/O devices in use by the caller process. Here, the new pro- cess legacy box gets linked to a channel, so that the copy(2) call would both block until the new process termi- nates and copy the process legacy to the stardard output device. Source /src/b/port/ulib.c and /src/b/port/plib.c See also proc(4).