[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
In Linux, creating a process is very interesting. As we all know, processes are the basic unit for enjoying Resources in the operating system. In Linux, how should we create a process? In fact, it is very simple, and a fork function can be done. However, we need to know that, apart fromCodeIs shared, stack data and global data are independent.
# Include <unistd. h> # include <stdio. h> # include <stdlib. h> # include <math. h> # include <errno. h> # include <sys/types. h> # include <sys/Wait. h> int main () {pid_t PID; If (-1 = (pid = fork () {printf ("error happened in fork function! \ N "); Return 0;} If (0 = PID) {printf (" this is child process: % d \ n ", getpid ());} else {printf ("this is parent process: % d \ n", getpid ();} return 0 ;}