166 lines · 3.7 KB · Text
RawDownload
.TH FORK 2.SH NAMEfork, rfork \- manipulate process resources.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.nf.Bint fork(void).PP.Bint rfork(int flags).fi.SH DESCRIPTIONForking is the only way new processes are created.The.I flagsargument to.I rforkselects which resources of theinvoking process (parent) are sharedby the new process (child) or initialized totheir default values.The resources includethe file name space,the open file descriptor table (which, when shared, permits processesto open and close files for other processes),the set of environment variables(see.IR env (3)),the note group(the set of processes that receive notes written to a member's.B notepgfile;see.IR proc (3)),the set of rendezvous tags(see.IR rendezvous (2)); and open files..I Flagsis the logical OR of some subset of.TF RFCNAMEG.TP.B RFPROCIf set a new process is created; otherwise changes affect thecurrent process..TP.B RFNOWAITIf set, the child process will be dissociated from the parent. Uponexit the child will leave no.B Waitmsg(see.IR wait (2))for the parent to collect..TP.B RFNAMEGIf set, the new process inherits a copy of the parent's name space;otherwise the new process shares the parent's name space.Is mutually exclusive with.BR RFCNAMEG ..TP.B RFCNAMEGIf set, the new process starts with a clean name space. A newname space must be built from a mount of an open file descriptor.Is mutually exclusive with.BR RFNAMEG ..TP.B RFNOMNTIf set, subsequent mounts into the new name space and dereferencingof pathnames starting with.B #are disallowed..TP.B RFENVGIf set, the environment variables are copied;otherwise the two processes share environment variables.Is mutually exclusive with.BR RFCENVG ..TP.B RFCENVGIf set, the new process starts with an empty environment.Is mutually exclusive with.BR RFENVG ..TP.B RFNOTEGEach process is a member of a group of processes that allreceive notes when a note is written to any of their.B notepgfiles (see.IR proc (3)).The group of a new process is by default the same as its parent, but if.B RFNOTEGis set (regardless of.BR RFPROC ),the process becomes the first in a new group, isolated fromprevious processes..TP.B RFFDGIf set, the invoker's file descriptor table (see.IR intro (2))is copied; otherwise the two processes share asingle table..TP.B RFCFDGIf set, the new process starts with a clean file descriptor table.Is mutually exclusive with.BR RFFDG ..TP.B RFRENDIf set, the process will be unable to.IR rendezvous (2)with any of its ancestors; its children will, however, be able to.B rendezvouswith it.  In effect,.B RFRENDmakes the process the first in a group of processes that share a space for.B rendezvoustags..TP.B RFMEMIf set, the child and the parent will share.B dataand.B bsssegments.Otherwise, the child inherits a copy of those segments.Other segment types, in particular stack segments, will be unaffected.May be set only with.BR RFPROC ..PD.PPFile descriptors in a shared file descriptor table are keptopen until either they are explicitly closedor all processes sharing the table exit..PPIf.B RFPROCis set, thevalue returned in the parent processis the process idof the child process; the value returned in the child is zero.Without.BR RFPROC ,the return value is zero.Process ids range from 1 to the maximum integer.RB ( int )value..I Rforkwill sleep, if necessary, until required process resources are available..PP.I Forkis just a call of.BR rfork(RFFDG|RFREND|RFPROC) ..SH SOURCE.B /sys/src/libc/9syscall.br.B /sys/src/libc/9sys/fork.c.SH SEE ALSO.IR intro (2),.IR proc (3),.SH DIAGNOSTICSThese functions set.IR errstr .