Basics on Process cooperation and operations on them in an operating system.
Size: 1.15 MB
Language: en
Added: Nov 12, 2020
Slides: 16 pages
Slide Content
Operations on Processes and Cooperating Processes - Vishnu Vijay Menon, S3 BCA
Operations On Processes Processes- as we know is an activity/ program under execution. Execution of a process is a complex activity. In modern day systems, processes are executed concurrently . Therefore, it is the duty of an operating system to provide a flexible mechanism for dynamically creating, maintaining and deleting processes in a computer system.
Operations performed while executing a process Creation
Process Creation Process creation is deemed to be the first step of any process execution activity. In simpler terms, it can be put as the construction of new processes for execution. There are four events that leads to the creation of a “new” process:- System Initialisation. Execution of a process creation system call by a running process. User request to create a new process. Initialization of a batch job.
-A new process is created using the system call “fork()” system call on UNIX systems [ CreateProcess() on Windows-based systems}. The one which initiates this call is termed as “Parent Process”; the one derived from it is termed as “Child Process”. -After the creation of a new process, the OS assigns a new Process identifier , an integer value to identify a process, which creates a new entry on the primary table. - Then, the required memory for all elements of a process such as program,data etc is allocated on Process Control Block. A thing to note is that depending the implementation of a system, some resources/data may be shared between a child and it’s parent process. In the beginning, not much is allocated to a process because a user has to request to do so but it’s child may inherit some resource from its parent.
Diagram of Creating a process using fork() Parent Process
After a child process is created, there are two options for the parent process: Wait for the child process to terminate before proceeding. The parent makes a wait() call. This is more common with UNIX based systems. Run concurrently with the child. A scenario where a parent process executes for a while and then pauses, for the child process to execute, is also possible
Process Termination All created processes have to be terminated at some point of their cycle. This is when a process is no longer needed for the program or some kind of problems may have been encountered by the program. A Process begins its termination when the final piece of the statement in a program is executed.
Types of Process Termination Normal Termination:- It is a type of voluntary termination, where the process quits after it has executed the final statement. The process may return a status value ( typically an integer) to the parent. The shared resources are also de-allocated by the OS. Abnormal Termination:- This type of termination occurs mostly due to programming errors,runtime errors, user intervention etc. There are three categories under this type of termination. Error Exit: A voluntary type termination which occurs due to program bugs( like trying to execute an illegal statement, referencing non existing memory etc.) In some cases in UNIX systems, the process requests the OS itself to rectify its own mistake, therefore only interrupting instead of terminating them.
2. Fatal Errors: It is an involuntary execution, in which there are problems in the code or a non existent file. 3. Killed by another process:- The Process may be terminated under the instruction of another process. This is invoked by an appropriate system call
A Parent may also terminate its Child when:- The task given to the Child is not needed anymore. The Child exceeds the usage of resources allocated to it. The Parent is exiting, resulting in the termination of the Child. Note: If the child is unable to be terminated since their Parent isn’t waiting, they will be returned to init and eventually be killed off.
Cooperating Processes There are many Processes which may be independent or cooperates with other processes in a program. As the name suggests, Independent Processes do not share any data and is not affected by any other process in any way. On the other hand, Cooperating processes may be affected by the other process in the system. A cooperating process is one that can affect or be affected by other process executing in the system cooperating process can: Directly share a logical address data space (i.e. code & data) - This may result in data inconsistency. It is implemented on threads. Share data only through files/ messages - It only deals with orderly execution of cooperating process so that data consistency is maintained.
Reasons that allow Process Cooperation Information Sharing: There may arise a scenario where every user wants the same piece of information. Thus, it allows concurrent access to all the data for everyone. Computation Speedup: A Process is expected to execute efficiently. So we breakup these processes into smaller sub tasks, where they will be parallely executing with one another. Modularity: Modular systems refers to a system that divides its functions into separate processes. Convenience: It enables the user to perform some tasks and run some programs at the same time.
Methods of Cooperation There are two ways: Cooperation by Sharing:- Processes can cooperate with each other by sharing data,memory,files,databases. Here, P1 and P2 share memory,variables,files,databases etc.
b) Cooperation by communication:- This method is generally tricky to execute. The processes in this method communicate through passage of messages. It may lead to a deadlock, if each process is waiting for a message. If it never receives, it may lead to starvation. In the diagram given, the processes communicate through messages.