Distinguish Parent and Child Process
Before we discuss in details, let's try the following code:
The output is as follows:
The original process has the PID 2072. After res = fork();
, the process splits into two, the parent and child.
For the parent, the return value of fork()
is the PID of the new child. However, for the child, the return value is 0.
By using this condition, we can distinguish parent and child.
Last updated