process creation and termination in operating system
TRANSCRIPT
![Page 1: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/1.jpg)
Process creation and termination
Agenda of Lecture
• Why and how process are created• Resource Sharing• Execution• Address Space• System Calls
![Page 2: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/2.jpg)
Process Creation
• Tree Hierarchy
Question: When a child Process is created , whether the child process will share info with their parent process and how its execution might be?
![Page 3: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/3.jpg)
Resource Sharing
They may settle three arrangements
1. Parent and children share all resources
2. Child and parent share subset of resources
3. They may share no resources
![Page 4: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/4.jpg)
Execution
Parent has created a child Process how their execution will go on
1. Parent stops waiting for child to finish itself2. Either they perform simultaneously3. Either parents end and child continues
![Page 5: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/5.jpg)
Unix & Linux
Unix / Linux Parent and child Process
Question: If they both look the same and usually if both the process of the same are running what will be the need of it to run?
![Page 6: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/6.jpg)
Unix & Linux ( Parent –Child)
System calls: Fork() To create a child Process Exit() To terminate a child Process Wait() Parent Process wait for a child
Process Exec() Process overwrites itself with
another executable program
![Page 7: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/7.jpg)
Process Tree in Unix
![Page 8: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/8.jpg)
Process Termination
Reasons:• The allocated resources to the child has been
exceeded• Parent Process has created lots of child
Process• Child Process was created for a purpose
whose task is completed
![Page 9: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/9.jpg)
System Calls ……• Fork()When the fork system call is executed a new process is created which consist of copy of the parent processThe mechanism allows parent process to communicate easily with the childSynopsis:#include <sys/types.h>#include<unistd.h>Pid_ t fork(void)
![Page 10: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/10.jpg)
![Page 11: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/11.jpg)
![Page 12: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/12.jpg)
![Page 13: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/13.jpg)
![Page 14: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/14.jpg)
![Page 15: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/15.jpg)
![Page 16: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/16.jpg)
![Page 17: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/17.jpg)
Wait()
• A process created a child process , process calls wait(), until a child process is terminated the parent process will remain in waiting state.
• Synopsis for wait system call#include <sys/types.h>#include <sys/wait.h>pid_t wait(int *stat_loc);
![Page 18: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/18.jpg)
Exec()
• A process that calls EXEC() it will overwrite itself with another executable
• There is no return value• Synopsis of execlp() is given as • #include <unistd.h>• int execlp (const char *file, const,char
*arg0, ...,const char *argn,(char *)Null);
![Page 19: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/19.jpg)
Sample Code
![Page 20: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/20.jpg)
Cooperating Processes
Advantages of Cooperating Process
• Information Sharing• Computation speedup• Modularity
![Page 21: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/21.jpg)
Producer Consumer Problem
• Over view of the ProblemWe may have processes which produce something, we place them some where (file/main memory) and then there are processes who will consume these things .The place where these items are placed can be bounded on unbounded
![Page 22: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/22.jpg)
Bounded Buffer consumer problem
• We call space a buffer which is bounded.• Process that creates an item place it in an
array slot called producer process• Process that consume the created item is
called consumer problem
![Page 23: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/23.jpg)
Buffer
• Buffer can be filled and empty .If producer produce item at faster rate then
consumer consumption then it may get full. In this case if the producer another item then it will have to wait
If the buffer is empty then the consumer is consuming at faster rate then producing so then the consumer will have to wait.
![Page 24: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/24.jpg)
General Problem Description
• We have fixed size buffer ,two processes( Producer and Consumer ) .Producer produce the item. Place it in the right full place in the buffer updates the index variable for the next item to place. Similarly index maintain the index variable which points to the next item to be consumed.
![Page 25: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/25.jpg)
Semantics of the problem
![Page 26: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/26.jpg)
Solution of the Problem
![Page 27: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/27.jpg)
Inter Process Communication
• The agenda is based on parent and child process communication.
• Channels required for communication• Properties of channels for different
communication • System calls ( Read and write )
![Page 28: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/28.jpg)
Operation for IPC
• Operation SendA process will send something to another process• Operation ReceiveA process will receive something form the sender processMessage that is sent may be unlimited or
bounded in terms of bytes
![Page 29: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/29.jpg)
Communication means
1. Direct Communication2. Indirect Communication
![Page 30: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/30.jpg)
Communication Channels
• Provide medium of communication• Both communication means employ medium of
communication• Few question to understand………a) How the channels are establish?b) How we may link two processesc) How many channels a cooperating process have?d) What is the capacity of the channels?e) Is the link is bidirectional or unidirectional?
![Page 31: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/31.jpg)
Direct Communication
• In direct Communication links are establish automatically
• Between each pair there would be one link• Link may be unidirectional or bidirectional
Name of the processMessage
![Page 32: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/32.jpg)
Indirect Communication
• Sender or receiver doesn’t name to sender process or receiver process and vice versa
• Example Mail Box• It is only possible if the process share the
same mail box ( Channel)
![Page 33: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/33.jpg)
Issues with indirect communication
• We have three processes P1, P2 and P3.P1 sends a message and P2,P3 are the receiver. Which Process will receive the message?
![Page 34: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/34.jpg)
Solutions
![Page 35: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/35.jpg)
Process Synchronization
![Page 36: Process creation and termination In Operating System](https://reader035.vdocuments.us/reader035/viewer/2022062406/55ce1301bb61ebde488b4781/html5/thumbnails/36.jpg)
Channels capacity