FORK SYSTEM CALL
AIM:
To write a c-program to implement fork system call.
ALGORITHM:
STEP 1: Start the program
STEP 2: Include the header file.
STEP 3: Declare the variable pid.
STEP 4: If pid=fork() is less than zero print "fork error".
STEP 5: Else if pid=0 print "child process" otherwise print "parent
Process.
STEP 6: Display the output.
STEP 7: Stop the program.
PROGRAM:
#include<stdio.h>
main()
{
int pid;
if((pid=fork())<0)
{
printf("fork error\n");
exit(1);
}
else if(pid==0)
{
printf("child process\n");
}
else
{
printf("parent process\n");
wait(0);
}
}
OUTPUT:
$ cc fork.c
$./a.out
Child process
Parent process