Parent and Child

Learn how to create a child process in C.

We'll cover the following

We have already learned, in the last lesson, that fork() replicates the code of the parent process in the child process. The code inside fork() is executed only once. Whereas, the rest of the code is executed twice. Therefore, there will be two return calls from the fork() function, even though it is only called once. fork() returns 0 on return from the child and returns the PID of a child from a parent. Let’s understand this scenario with the help of an example program.

Example program

See the code given below:

Get hands-on with 1200+ tech skills courses.