PCB Ststes Process
PCB Ststes Process
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.
A process moves from run state to block or wait state if it requires an I/O operation
or some blocked resource during its execution.
After the I/O operation gets completed or resource becomes available, the process
moves to the ready state.
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.
A process moves from ready state to suspend ready state if a process with higher
priority has to be executed but the main memory is full.
Moving a process with lower priority from ready state to suspend ready state
creates a room for higher priority process in the ready state.
The process remains in the suspend ready state until the main memory becomes
available.
When main memory becomes available, the process is brought back to the ready
state.
Suspend Wait State
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.
A process moves from wait state to suspend wait state if a process with higher
priority has to be executed but the main memory is full.
Moving a process with lower priority from wait state to suspend wait state creates
a room for higher priority process in the ready state.
After the resource becomes available, the process is moved to the suspend ready
state.
After main memory becomes available, the process is moved to the ready state
Process Control Block (PCB)
Process Control Block (PCB) is a data structure that stores information about a
particular process.
Process ID-
Program Counter-
Before execution, program counter is initialized with the address of the first
instruction of the program.
After executing an instruction, value of program counter is automatically
incremented to point to the next instruction.
Process State-
Priority-
Process with the highest priority is allocated the CPU first among all the processes.
General purpose registers are used to hold the data of process generated during its
execution.
Each process has its own set of registers which are maintained by its PCB.
Each process requires some files which must be present in the main memory
during its execution.
PCB maintains a list of files used by the process during its execution.
PCB maintains a list of open devices used by the process during its execution.
Privileged Access: The kernel space is a privileged area of the operating system,
where critical system functions are executed. PCBs need to be managed and
maintained by the operating system, and the kernel space is where this
management occurs.
Process Creation
The Fork system call is used for creating a new process in Linux, and Unix
systems, which is called the child process, which runs concurrently with the
process that makes the fork() call (parent process).
After a new child process is created, both processes will execute the next
instruction following the fork() system call.
Positive value: Returned to parent or caller. The value contains the process ID of
the newly created child process.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
pid_t p ;
p= fork();
if(p<0){
return 0;
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
fork();
fork();
fork();
printf("Happy\n");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
pid_t p;
p = fork();
if(p<0)
perror("fork fail");
exit(1);
}
// child process because return value zero
else if ( p == 0)
else
int main()
forkexample();
return 0;