You are on page 1of 5

BARIRA AKBAR

BSE IVA
OPERATING SYSTEM
LAB 05

SUBMITTED TO
Ms. Muhammad Shahzad
DEPARTMENT OF SOFTWARE
ENGINEERING
FATIMA JINNAH WOMEN UNIVERSITY
Department Of Software Engineering
Example 1:

Example 2:
Part 1:
Part 2:

Task 01

Task 02
#include<sys/types.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<stdio.h>
#include<unistd.h>
int main()
{pid_t children,first,second;
int temp,status;
if((first=fork())== 0)
{
printf("I am first child and My Id is %d\n",getpid());
exit(0);
}
else if((second =fork())== 0)
{printf("I am Second child and My Id is %d\n",getpid());
exit(0);
}
printf("I am Parent\n");
temp = 0;
while (temp<2)
{children = wait(&status);
temp++;
if(children == first)
printf("First child exited\n");
else
printf("Second child exited\n");}}
THE END

You might also like