ramansingh202211111
34 views
11 slides
Jun 04, 2024
Slide 1 of 11
1
2
3
4
5
6
7
8
9
10
11
About This Presentation
It is the file containing fork()
System call used in OS and linux for copy and duplicating any process .
Size: 1.14 MB
Language: en
Added: Jun 04, 2024
Slides: 11 pages
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