0% found this document useful (0 votes)
3 views

Lab 5

The document explains the fork(), exit(), and wait() system calls in operating systems. It describes how fork() creates a child process, exit() terminates a process, and wait() blocks a process until a child exits. Additionally, it includes lab tasks related to these system calls, such as creating multiple child processes and printing numbers through child processes.

Uploaded by

ranahassan7674
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab 5

The document explains the fork(), exit(), and wait() system calls in operating systems. It describes how fork() creates a child process, exit() terminates a process, and wait() blocks a process until a child exits. Additionally, it includes lab tasks related to these system calls, such as creating multiple child processes and printing numbers through child processes.

Uploaded by

ranahassan7674
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Hanzala Haroon

F2022266697

What is fork () system call?


fork () creates a new child process. If we call fork () in the parent program, it creates a child
process which shares an exact copy of the address space but a different one.
Example # 01:

Output:

1
We can distinguish child and parent processes because fork () returns 0 inside the child
process and returns a positive integer inside the parent process

Example #2

Output:

2
What is Exit System Call?
The call to exit () terminates the calling process without executing the rest code which is after
the exit () function

Syntax:

Example:

3
Output:

What is Wait System Call?


A call to wait () blocks the calling process until one of its child processes exits or a signal is
received.
 It calls exit ();

4
 It returns (an int) from main
Example # 1

Output:

Lab Task
1. Call fork () system call three times in a process and display a msg. What will be the
output and also explain your output? i.e how many childrens are created and what
trend they are following. How many child process will be created if fork () is called
four times?

5
Output

6
2. Print first 5 odd numbers through child process. Parent process must wait for the child
process then after 2 seconds delay pddarent process should display first 5 prime
numbers.

Output

7
Task 3

You might also like