Professional Documents
Culture Documents
Write c program using fork system call to create a process and study parent child mechanism
#include <stdio.h>
#include<unistd.h>
#include<sys/types.h>
void forkexample(void);
void forkexample()
int a = 10;
if(fork()==0)
else
void main()
forkexample();
Output:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
void main()
{
ret = fork();
if(ret == 0)
else
count = 1;
OUTPUT:
The parent executes the statement ”count = 1” before the child executes for the first time. Now,
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
void main()
if(ret == 0) {
printf("Hello1\n");
printf("Hello2\n");
printf("Hello3\n");
} else {
printf("Hello4\n");