0% found this document useful (0 votes)
37 views16 pages

PCB Ststes Process

Uploaded by

Muhammad Tanveer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views16 pages

PCB Ststes Process

Uploaded by

Muhammad Tanveer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 16

New State

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.

Block or Wait State

If a process requires an Input/Output operation or a blocked resource during


execution, it changes from run to block or the wait state.
The process advances to the ready state after the I/O operation is completed or the
resource becomes available.

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.

Suspend 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.

This information is required by the CPU while executing the process.

The PCBof a process looks like-


Each process is identified by its own process control block (PCB).

It is also called as context of the process.

Process ID-

Process Id is a unique Id that identifies each process of the system uniquely.

A process Id is assigned to each process during its creation.

Program Counter-

Program counter specifies the address of the instruction to be executed next.

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.

This process repeats till the end of the program.

Process State-

Each process goes through different states during its lifetime.

Process state specifies the current state of the process.

Priority-

Priority specifies how urgent is to execute the process.

Process with the highest priority is allocated the CPU first among all the processes.

General Purpose Registers-

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.

List of Open Files-

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.

List of Open Devices-

PCB maintains a list of open devices used by the process during its execution.

PCB of each process resides in the main memory.

There exists only one PCB corresponding to each process.

PCB of all the processes are present in a linked list.

Where the PCB is stored?


Process Control Blocks (PCBs) are typically stored in the operating system's space,
specifically in the kernel space. The PCB contains critical information about a
process, and it is used by the operating system to manage and control the execution
of processes efficiently. Storing PCBs in the kernel space ensures that the operating
system has direct and privileged access to this information.
Security: The information within a PCB is sensitive and must be protected from
unauthorized access and modification. Placing PCBs in the kernel space provides
an additional layer of security, as user-level processes cannot directly access or
tamper with this data.

Efficiency: Accessing PCB information quickly is crucial for process


management, scheduling, and resource allocation. Placing PCBs in the kernel
space allows the operating system to access this data efficiently and make
decisions based on it.

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.

It takes no parameters and returns an integer value.

Negative Value: The creation of a child process was unsuccessful.

Zero: Returned to the newly created child process.

Positive value: Returned to parent or caller. The value contains the process ID of
the newly created child process.

Example code for the process creation

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

int main()

{ // make two process which run same

// program after this instruction

pid_t p ;

p= fork();

if(p<0){

perror("fork fail"); //perror() is a standard library function in C, defined in the


stdio.h and stdlib.h headers.

exit(1);//The error occured and this function is defined in stdio.h


}

printf("Hello world!, process_id(pid) = %d \n",getpid());

return 0;

Second Example for the process creation

#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)

printf("Hello from Child!\n");

// parent process because return value non-zero.

else

printf("Hello from Parent!\n");

int main()

forkexample();

return 0;

You might also like