Social Icons

Saturday, 27 April 2013

Creating Child Process Using Fork


#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t pid;
pid=fork();
int n;
char *m;
switch(pid)
{
case -1  : printf("\n Error ocured : ");
           break;
case 0 :
              n=3;
            m="child process is running : ";
             break;
default :
              n=3;
            m="parent process is running : ";
                 break;
}


for(;n>0;n--)
{
 puts(m);
 sleep(1);


}

return 0 ;
}


Output :
 

No comments:

Post a Comment

 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management