PROCESS CREATION USING FORK () USING C PROGRAM

AIM:
To write a C program to perform process creation using fork() system call . OPERATING SYSTEM (OS) LAB IN LINUX ENVIRONMENT
ALGORITHM:
· Start program.
· Assign fork() system call to pid.
· if pid is equal to -1, child process not created.
· if pid is equal to 0, child process will be created.
· Print the id of parent process and child process.
· Create another one child process in same loop.
· Print id of parent process and the child process.
· Print grand parent id.
· Stop the program.

PROGRAM SOURCE CODE


#include<sys/types.h>
#include<stdio.h>
#include<process.h>
int main()
{
int pid_t,pid,pid1,p,p1;
pid =fork();
if (pid ==-1)
{
printf("enter in connection");
}
else
if(pid==0)
{
printf("\n child process1 :\n\n");
p=getppid();
printf("parent process id of child1: %d\n",p);
p1=getpid();
printf("parent process id of child1: %d\n",p1);
}
else
{
pid1=fork();
if(pid==0)
{
printf("\nchild process 2:\n\n");
p=getppid();
printf("parent process id of child2: %d\n",p);
p1=grtpid();
printf("parent process id of child2: %d\n",p1);
}

else
{
printf("this is parent process \n");
p=getppid();
printf("grant parent: %d \n",p);
p1=getpid();
printf("process id of parent: %d \n",p1);
}
}
return 0;
}

CONCLUSION:
Thus the c program to perform process creation using fork() was written and executed successfully.

Related post