Operating system Notes
Introduction of Operating System
PROCESS: Program to process, Lifecycle of the process, Process control block, IPC
Protection And Security
What is a process?
A program in execution is called a process. A program becomes a process when it is loaded into the main memory for execution. A process is the basic unit of execution in a computer system. It is an ‘active’ entity, while program is a ‘passive’ entity.
A process is divided into four segments in the memory. The memory layout of a process is given below:
Stack is used to store temporary data such as return address, local variables and function parameters. The return address is the address of the instruction which has to be executed after the completion of function execution. The stack grows from lower address to higher address and it follows the LIFO mechanism.
Heap is used for dynamic memory allocation. It is used to allocate memory to the variables while the execution of a process. It is used by the malloc() and calloc() functions.
The data section is used to store the global and static variables. This region remains static throughout the process execution. It is also called BSS (Block Started by Symbol)
This region stores the instructions in the process. It is also called the Code Segment. It stores the values in the CPU registers and the program counter.
Explain different types of process present in os.
The processes can be divided into two broad classes. They are:
Independent processes do not depend on each other. i.e. one process cannot affect another process. These processes do not share their data with each other or with the system.
Cooperative processes depend on each other for execution. They share data with the other processes. The execution of such processes is affected by the other processes in the system.
Explain various process states.
This state is the initial state of every process that is being created. Whenever a process is created, the process is in the New state.
When a process is ready to run, it enters the Ready state. i.e. when a process is loaded into the main memory and is waiting to be executed by the processor, the process remains in the Ready state.
A process is in the ready suspended state when it is moved into the secondary memory from the main memory due to lack of storage space. When there is no sufficient space in the main memory for the process, the process is suspended and moved to the secondary memory. This state of the process is called the ‘ready suspended’ state.
When the process is being executed, it is in the ‘running’ state.
Blocked or wait
The process is in the ‘wait’ state when it requests for I/O access from the processor. The process remains in the wait state until the I/O operation is complete. Once the I/O operation is over, the process returns to the ‘ready’ state.
This state is similar to the ‘ready suspended’ state except for the fact that the process is suspended when that process is in ‘blocked’ state. i.e. when the process is waiting for an I/O operation to be complete.
If the process has completed its execution, it enters this state. Once the process is terminated, the PCB of the process is deleted and the process is deleted from the main memory.
What is PCB.Explain its significance.
The Process Control Block (PCB) contains information about the process. It contains the information about the execution status of the process. The operating system uses the PCB to keep track of all the processes in a multiprogramming system.
Whenever a process is created, a PCB is also created for that particular process. The PCB contains the information about the process id, program counter, process state, priority etc., When the process is transferred from one state to another, the data is updated in the PCB.
When a process is created, it is assigned a unique id. This is called process id.
This field mentions the current state of the process.
This field mentions the priority of the process
Program counter contains the address of the next instruction to be executed.
Significance of PCB
As the PCB keeps track of all the processes, it is very much useful is multiprogramming.
It gives a detailed account on the resources used by the process.
It records the execution status of the process.
What role does operating system plays in process management?
The following are the different tasks performed by the operating system in process management:
The operating system decides the order of execution of the processes. The process scheduling is done based on the process priority. The OS also decides the execution time of the process.
The operating system allocates and deallocates the resources to the processes according to their requirement.
The operating system keeps track of the states of a process. It allocates and deallocates the processes to the processor. Hence, the OS is called a traffic controller.
When a deadlock occurs, the operating system takes steps to recover from the deadlock. Hence, the OS is involved in deadlock handling.
Explain various types of schedulers in an os?
The different types of schedulers are explained below:
Long term scheduler
The long term scheduler controls the degree of multiprogramming. It selects the processes for execution such that the CPU utilization is maximized. Hence, the long term scheduler directly determines the efficiency of a system.
The main job of the long term scheduler is to load the programs from the disk to the primary. It selects the I/O and CPU bound processes from the disk such that the CPU is utilized efficiently.
Medium term scheduler
The medium term scheduler is responsible for swapping the processes in and out of the main memory. It suspends and resumes the execution of the processes. It is helpful in reducing the degree of multi-programming of the system.
Short term scheduler
The short term scheduler is used to assign the processes in the ready state for execution. It decides the order in which the processes must be executed.
It is called a short term scheduler because it executes more frequently than the other schedulers. This is due to the fact that the processes take only a few milliseconds for execution.
What is the difference between I/O bound and CPU bound process?
Explain Context Switch, Synchronization, dispatch latency
Context switching is the process which is done when the processor switches from one process to another. The context of one process is saved and the context of another process is loaded into the memory. The context of a process refers to the data in the program counter, and CPU registers at that instance of time.
In other words, the process of changing the state of a process from ‘running’ to ‘ready’ is called context switching.
Process synchronization refers to the sharing of resources between processes, without causing any inconsistency. The main aim of process synchronization is to maintain data consistency in the system and to prevent race condition.
It is very much required when the processes have to be executed concurrently. It is used to achieve the coordination of process interactions in the computer system.
The dispatch latency is the time taken by the dispatcher to stop one process and start another.
The dispatcher is responsible for moving the process from the ready state to the running state. It gives the CPU control to the process. The time taken by the dispatcher in this process is called dispatch latency.
What are the different ways of resource sharing between parent and children processes?
The following are the different methods of resource sharing between the parent and the child processes:
a.Parent and child share all the resources
b.Child shares a subset of parent’s resources.
c.Parent and child do not share any resources
What do you understand by System calls?
The system call acts as an interface between the user program and the operating system. The user program requests a service from the OS kernel through a system call. System calls are used for process management, file management, resource management etc.,
The system calls are usually assembly language programs which directly communicate with the kernel.