Home>Article>Backend Development> In C language, the fork() function
In this section, we will learn about the fork system call in C language. The fork system call is used to create a new process. This newly created process is called a child process. The current process that creates another child process is called the parent process.
The child process uses the same program counter, CPU registers, and the same files used by the parent process.
The fork() function does not accept any parameters, it returns an integer value. It may return three types of integer values.
Negative number: When the child process creation fails, a negative number is returned
Zero value: For newly created child processes, return zero
positive number: A positive number is returned to the parent process.
#include#include #include int main() { fork(); //make a child process of same type printf("Fork testing code "); return 0; }
soumyadeep@soumyadeep-VirtualBox:~$ ./a.out Fork testing code soumyadeep@soumyadeep-VirtualBox:~$ Fork testing code soumyadeep@soumyadeep-VirtualBox:~$
The above is the detailed content of In C language, the fork() function. For more information, please follow other related articles on the PHP Chinese website!