fork is an operation or a process which creates a copy of itself. It is usually a system call, implemented in the kernel. Fork is the primary method of process creation on Unix-like operating systems.
- If fork() returns a negative value, the creation of a child process was unsuccessful.
- fork() returns a zero to the newly created child process.
- fork() returns a positive value, the process ID of the child process, to the parent. The returned process ID is of type pid_t defined in sys/types.h. Normally, the process ID is an integer. Moreover, a process can use function getpid() to retrieve the process ID assigned to this process.
Due to the fact that the CPU scheduler will assign a particular time to each process, the parent or the child process will run for some time.After the calling of system call FORK the program counter of both will run simultaneously.