Practice mode Operating Systems

What does the fork() system call return to the child process when it succeeds?

Correct answer A. 0

Explanation

On success fork() returns twice: the parent receives the new child's PID, while the child receives 0. This difference is how the code tells which copy it is running in. A return of -1 occurs only in the parent when the call fails and no child is created. The child can obtain its parent's PID with getppid() rather than from fork().

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.