1. Comparison of several creation process functions
? #fork ():
? Source
? ? Execution results:
? ? ? In the parent process!
? ? ? In the child process!
? Analysis: Fork () Call once, return two times, respectively, in parent process and child process return (but order indeterminate)
? ? ?
? #vfork ()
? ? Source code:
? ? Execution results:
? ? ? Process id:12845
? ? ? gvar=2 var=5the child process id:12846
? ? ? gvar=1 var=6
? ? ? The parent process id:12845
? ? ? gvar=1 var=6
? Analysis: If you change the vfork () to fork (), the input result becomes:
? ? ? ? ? ? Process id:12856
? ? ? ? ? ? gvar=2 var=5the Parent Process id:12856
? ? ? ? ? ? gvar=2 var=5
? ? ? ? ? ? gvar=2 var=5the child process id:12857
? ? ? ? ? ? gvar=1 var=6
? ? ? ? Description, fork () copies the resources of the parent process when the process is created, and vfork () does not replicate the parent process resource, sharing the address space with the parent process. ?
? ? ?
Functions in the linux-process Control