Home » NO IDEA » Forking -creation of new process

Forking -creation of new process

Blog Stats

  • 15,880 hits
April 2013
M T W T F S S
« Mar   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

A new process cam be created using the system call called fork()

in order to use the fork command use the header called <unistd>,<sys/types.h>

when fork is executed new process is created which is called as the child process while the process which created the child process is called the parent process

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main( )
{
printf ( "Before Forking\n" ) ;
fork( ) ;
printf ( "After Forking\n" ) ;
}

 

output:

Before Forking
After Forking
After Forking

fork() creates a child process and duplicates the code of the parent process in the child process.there on wards the execution of the fork() function continues in both the processes.Thus ,the duplication code inside fork() is executed once.whereas, the remaining code inside it is executed in both the parent as well as the chold process.As against this, when control returns from fork() of the child process,it always returns a 0.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: