Monday 8 September 2014

Fork() in linux

fork ():
This glibc wrapper is used to create a child process. Modern fork () is implemented using copy-on-write pages.  The child only receives a new copy of a memory page when it tries to make a change to something in that page. Until then, it simply uses the parent's copy. This is called copy-on-write.

This system call, along with the class of exec system calls (ie.  execl(), execlp()execv(), execvp()) is actually the way for shell to executes programs given on the command line.

Prototype:

#include <unistd.h>
pid_t fork(void);

In case of failure: It returns negative error number for ENOMEM, EAGAIN etc
In case of success: It returns 0 to new child process and PID of child process to parent process.





No comments:

Post a Comment