C PROGRAM TO IMPLEMENT FORK SYSTEM CALL (WITH ALGORITHM)
AIM : TO IMPLEMENT FORK SYSTEM CALL
ALGORITHM :
STEP 1 : START
STEP 2 : CREATE A CHILD PROCESS USING FORK
STEP 3 : IF THE PROCESSID EQUALS 0 GOTO STEP 4 ELSE GOTO STEP5
STEP 4 : IT IS A CHILD PROCESS AND GET ITS ID AND PARENT PROCESSID
STEP 5 : IF PROCESSID>0 IT IS A PARENT PROCESS AND GET ITS ID
STEP 6 : HANDLE THE SYSTEM INTERRUPT(ERROR)
STEP 7 : STOP
PROGRAM :
#include<stdio.h>
void main()
{
int pid;
pid=fork();
if(pid==0)
{
printf("\n child process ");
printf("\n pid of child process : %d \n pid of parent process : %d\n",getpid(),getppid());
}
else if(pid>0)
printf("\n parent process : %d",getpid());
else
printf("\n error");
}
OUTPUT :
parent process : 3248
child process
pid of child process : 3249
pid of parent process : 1
AIM : TO IMPLEMENT FORK SYSTEM CALL
ALGORITHM :
STEP 1 : START
STEP 2 : CREATE A CHILD PROCESS USING FORK
STEP 3 : IF THE PROCESSID EQUALS 0 GOTO STEP 4 ELSE GOTO STEP5
STEP 4 : IT IS A CHILD PROCESS AND GET ITS ID AND PARENT PROCESSID
STEP 5 : IF PROCESSID>0 IT IS A PARENT PROCESS AND GET ITS ID
STEP 6 : HANDLE THE SYSTEM INTERRUPT(ERROR)
STEP 7 : STOP
PROGRAM :
#include<stdio.h>
void main()
{
int pid;
pid=fork();
if(pid==0)
{
printf("\n child process ");
printf("\n pid of child process : %d \n pid of parent process : %d\n",getpid(),getppid());
}
else if(pid>0)
printf("\n parent process : %d",getpid());
else
printf("\n error");
}
OUTPUT :
parent process : 3248
child process
pid of child process : 3249
pid of parent process : 1
No comments:
Post a Comment