Using Linux System Calls Program Operating Systems Lab

By | December 18, 2022

Using Linux System Calls Program Operating Systems Lab – Write a C program Using Linux System Calls Program to create a child process using fork() system call.
Display suitable message about parent process ID, child process or Error message if child process could not be created.

Using Linux System Calls Program fork() getpid() Operating Systems Lab

Program Code using fork() getpid() and exit()

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
int pid,pid1,pid2;
pid=fork();
if(pid==-1)
{
printf("ERROR IN PROCESS CREATION \n");
exit(1);
}
if(pid!=0)
{
pid1=getpid();
printf("\n the parent process ID is %d\n", pid1);
}
else
{
pid2=getpid();
printf("\n the child process ID is %d\n", pid2);
}
return 0;
}

Output

the parent process ID is 319

the child process ID is 323

You may also like to read more Operating system Lab Practical Programs:

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *