Friday, September 21, 2012

What is the difference between exec and fork?

fork creates a new process by replicating itself (file descriptors, etc) to a subshell and runs the forked process in that subshell via exec. The new process acts as an independent process in separte memory space with its own unique process ID. It creates a Parent-Child relationship wherin the child returns its PID to parent and the parent provides zero on successful fork.

exec, on the other hand, executes the given process by replacing the current process. exec doesn't return any value on success. It shares the same memory space for the new process.

No comments :