linux-sysprog · beginner · ~15 min
Decode the three-way meaning of fork's return value.
fork() returns <0 on error, 0 in the child, and the child PID (>0) in the parent. Implement int fork_role(int ret) returning -1, 0, or 1 for error, child, parent.
int fork_role(int ret) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.