Hello Friends, In this blog post we are going to discuss Fork and Exec system calls. In UNIX, each process is identified by its process identifier, which is a unique integer. A new process is created by the fork system call. The new process consists of a copy of the address space of the original process.
What are fork () Vfork () and exec ()?
A fork system call is used for creating a new process. This new process becomes the child process.
Once this new child process is created then both the process parent and child process execute the next instruction as per the fork() system call.
Vfork is different from the fork system call in the context where Vfork creates the new child process and then the parent process gets suspended temporarily.
This child process also takes or borrows the address space of the parent process.
Exec() system call replaces the current process with a new executable process or program.
This mechanism allows the parent process to communicate easily with its child process. Both processes continue execution at the instruction after the fork system call, with one difference ——-
The return code for the fork system call is zero for the new (child) process, whereas the (nonzero) process identifier of the child is returned to the parent.
Typically the exec system call is used after a fork system call by one of the two processes to replace the process memory space with a new program.
In the multithreaded program, the semantics of the fork and exec system call change. If one thread in a program calls fork, does the new process duplicate all threads, or is the new process single-threaded?
Some Unix systems have chosen to have two versions of the fork, one that duplicates all threads and another that duplicates only the thread that invoked the fork system call.
If a thread invokes the system call, the program specified in the parameter to exec will replace the entire process- including all threads and LWPs.
The usage of the two versions of the fork depends upon the application. If exec is called immediately after forking, then duplicating all threads is unnecessary, as the program specified in the parameters to exec will replace the process.
In this instance, duplicating only the calling thread is appropriate. if however, the separate process does not call exec after forking, the separate process should duplicate all threads.
You can also go through a few more amazing blog links below related to operating systems:
disk scheduling क्या होती है…
FAT32 Advantages and Disadvantages…
Overlay advantages and disadvantages in programs…
What is the use of Cache Memory…
What is Linker? Why is it required?…
types Of File Operations…
What are the file Organisation and its types…
Dijkstra: Bankers Algorithm For Deadlock Avoidance…
What is a thread in the operating system with an example…
Cache Memory In Hindi…
Linker In Hindi…
What Are Multithreading Models in Hindi…
Dynamic Storage Problem In OS In Hindi…
Process states in the Operating system in Hindi…
FAT32 Advantages And Disadvantages In Hindi…
Critical Section Problem With a Simple Example…
Critical Section Problem In OS In Hindi…
Dijkstra Algorithm In Hindi|Banker’s Algorithm In Hindi…
What Is Dynamic Storage Problem…
What are the Fork and Exec system calls…
Multithreaded Process: Benefits & Models…
The Process States In Operating System…
In the case of any queries, you can write to us at a5theorys@gmail.com we will get back to you ASAP.
Hope! you would have enjoyed this post about the Fork() and Exec() system call.
Please feel free to give your important feedback in the comment section below.
Have a great time! Sayonara!