Fork System call
fork() system call
fork() is a system call. fork is used to create a child process from the running process, which is a replica of the parent process(Process which executed
fork() ). Child process is derived from the parent process. Both the parent and child have different address space, each is independent of the changes made to the variables.
The child process has its own PID(process identification). PPID(Parent Process ID) of child process is same as PID of parent process.
Header file :
Function Declaration :
fork() doesn't need any input arguments.
On successful creation of child process the pid of the child process is returned to the parent process and 0 is returned in the child process. On Failure return
-1 with no process created.
The sequence of the
printf statements from the child and parent depend on the scheduling mechanism which purely depends on the system.