Thursday, October 11, 2012

The fork(), exec() system call



  • fork():

The fork system call does not take an argument.
When a fork() system call is made, the operating system generates a copy of the parent process which becomes the child process.

The following is a simple example of fork()
#include
#include
#include

int main(void)
{
   printf("Hello \n");
   fork();
   printf("bye\n");
   return 0;
}

Hello - is printed once by parent process
bye - is printed twice, once by the parent and once by the child


  • exec*()


"The exec family of functions replaces the current process image with a new process image." (man pages)

http://www.cs.uregina.ca/Links/class-info/330/Fork/fork.html

No comments:

Post a Comment