Fork() for the OS of MNNIT system call.pptx

ramansingh202211111 34 views 11 slides Jun 04, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

It is the file containing fork()
System call used in OS and linux for copy and duplicating any process .


Slide Content

Fork() system call Operating System

Introduction The fork system call allows the creation of a new process. When a process calls the  fork(), it duplicates itself, resulting in two processes running at the same time. The new process that is created is called a  child process . It is a copy of the parent process. 2

Process Creation When the fork system call is used, the operating system completely copies the parent process to produce a new child process. The child process uses same program counter, CPU register, memory and open file descriptors. The new  process has its own address space , and memory. However, it has a unique PID . 3

Child Process Fork system call returns an integer value. Negative value : Represents the creation of the child process was unsuccessful. Zero :  Represents a new child process is created. Positive value : Returned the PID  of the child process to the parent. 4

f ork() The following header files are included when we use fork() in C. #include < stdio.h > #include < unistd.h > #include <sys/ types.h > fork() is defined in < unistd.h > header file Type pid_t is defined in <sys/ types.h > and process ID’s are of pid_t type. 5

f ork() 6

7 Output: Here, the total number of processes created is 2^3 = 8 T he print statement is executed eight times.

8 Output: This is the parent process This is the child process

9 Output In the child, the value of x is 4 In the parent, the value of x is 2 Or  In the parent, the value of x is 2 In the child, the value of x is 4

10 Output Hello world!, process_id ( pid ) = 31 Hello world!, process_id ( pid ) = 32

THANK YOU
Tags