Process in Operating System
Process in Operating System
2 Process privileges
This is required to allow/disallow access to system resources.
3 Process ID
Unique identification for each of the process in the operating system.
4 Pointer
A pointer to parent process.
5 Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this
process.
6 CPU registers
Various CPU registers where process need to be stored for execution for running state.
9 Accounting information
This includes the amount of CPU used for process execution, time limits, execution ID etc.
10 IO status information
This includes a list of I/O devices allocated to the process.
The architecture of a PCB is completely dependent on Operating System and may contain
different information in different operating systems. Here is a simplified diagram of a PCB −
The PCB is maintained for a process throughout its lifetime, and is deleted once the process
terminates.
When a program in secondary memory is started for execution, the process is said to be in a new
state.
Ready State
After being loaded into the main memory and ready for execution, a process transitions from a
new to a ready state. The process will now be in the ready state, waiting for the processor to
execute it. Many processes may be in the ready stage in a multiprogramming environment.
Run State
After being allotted the CPU for execution, a process passes from the ready state to the run state.
Terminate State
When a process’s execution is finished, it goes from the run state to the terminate state. The
operating system deletes the process control box (or PCB) after it enters the terminate state.
The process advances to the ready state after the I/O operation is completed or the resource
becomes available.
If a process with a higher priority needs to be executed while the main memory is full, the
process goes from ready to suspend ready state. Moving a lower-priority process from the ready
state to the suspend ready state frees up space in the ready state for a higher-priority process.
Until the main memory becomes available, the process stays in the suspend-ready state. The
process is brought to its ready state when the main memory becomes accessible.
If a process with a higher priority needs to be executed while the main memory is full, the
process goes from the wait state to the suspend wait state. Moving a lower-priority process from
the wait state to the suspend wait state frees up space in the ready state for a higher-priority
process.
The process gets moved to the suspend-ready state once the resource becomes accessible. The
process is shifted to the ready state once the main memory is available.
An active process is normally in one of the five states in the diagram. The arrows show how it
changes states.
A process is runnable in memory if it is in primary memory and ready to run, but is not
assigned to a CPU.
A process is runnable and swapped if it is not waiting for a specific event but has had its
whole address space written to secondary memory to make room in primary memory for
other processes.
A process is sleeping and swapped if it is both waiting for a specific event and has had its
whole address space written to secondary memory to make room in primary memory for
other processes.
If a machine does not have enough primary memory to hold all its active processes, it must page
or swap some address space to secondary memory.
When the system is short of primary memory, it writes individual pages of some
processes to secondary memory but still leaves those processes runnable. When a process
runs, if it accesses those pages, it must sleep while the pages are read back into primary
memory.
When the system gets into a more serious shortage of primary memory, it writes all the
pages of some processes to secondary memory and marks those processes as swapped.
Such processes get back into a state where they can be scheduled only by being chosen
by the system scheduler daemon process, then read back into memory.
Both paging and swapping cause delay when a process is ready to run again. For processes that
have strict timing requirements, this delay can be unacceptable.
Process Scheduling
The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a particular
strategy.
Categories of Scheduling
1. Non-preemptive: Here the resource cant be taken from a process until the process
completes execution. The switching of resources occurs when the running process
terminates and moves to a waiting state.
2. Preemptive: Here the OS allocates the resources to a process for a fixed amount of time.
During resource allocation, the process switches from running state to ready state or from
waiting state to ready state. This switching occurs as the CPU may give priority to other
processes and replace the process with higher priority with the running process.
As shown in Figure 4.1, multi-threaded applications have multiple threads within a single
process, each having their own program counter, stack and set of registers, but sharing
common code, data, and certain structures such as open files.
Figure 4.1 - Single-threaded and multithreaded processes
Types of Threads
In the operating system, there are two types of threads.
1. Kernel level thread.
2. User-level thread.
1) User-level thread
The operating system does not recognize the user-level thread. User threads can be easily
implemented and it is implemented by the user. If a user performs a user-level thread blocking
operation, the whole process is blocked. The kernel level thread does not know nothing about the
user level thread. The kernel-level thread manages user-level threads as if they are single-
threaded processes? Examples: Java thread, POSIX threads, etc.
Advantages of User-level threads
1. The user threads can be easily implemented than the kernel thread.
2. User-level threads can be applied to such types of operating systems that do not support
threads at the kernel-level.
3. It is faster and efficient.
4. Context switch time is shorter than the kernel-level threads.
5. It does not require modifications of the operating system.
6. User-level threads representation is very simple. The register, PC, stack, and mini thread
control blocks are stored in the address space of the user-level process.
7. It is simple to create, switch, and synchronize threads without the intervention of the
process.
Disadvantages of User-level threads
1. User-level threads lack coordination between the thread and the kernel.
2. If a thread causes a page fault, the entire process is blocked.
2) Kernel level thread
The kernel thread recognizes the operating system. There is a thread control block and process
control block in the system for each thread and process in the kernel-level thread. The kernel-
level thread is implemented by the operating system. The kernel knows about all the threads and
manages them. The kernel-level thread offers a system call to create and manage the threads
from user-space. The implementation of kernel threads is more difficult than the user thread.
Context switch time is longer in the kernel thread. If a kernel thread performs a blocking
operation, the Banky thread execution can continue. Example: Window Solaris.