Medium Operating Systems Processes & Threads
Explain fork() and exec() system calls and their relationship.
Answer
fork() creates a new process by duplicating the calling process - child gets copy of parent's memory (copy-on-write optimization), file descriptors, but new PID. Returns child PID to parent, 0 to child. exec() family replaces current process image with new program - same PID but new code/data. Common pattern: fork() then exec() to run new program. Parent can wait() for child completion. This separation allows child to set up (redirects, pipes) before exec.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Software Engineer Systems Developer Backend Developer