Everything you need to know about process management in operating system

Everything you need to know about process management in operating system

·

10 min read

Process Management in Operating System

What is Process?

The Program in execution is called process. A Program that is currently executed by CPU is called process. It is basic function of operating system to manage the process. OS manages the process in three steps.

  1. Recognition

  2. Preparation

  3. Execution

Recognition:

When user issue a command then it is request for operating system then OS will check whether it is an internal command or external command, Internal command (a command which operating system knows and its exe is in OS files) if it is an external command then OS will check whether it is valid command or not if it is a valid command then task is verified.

Preparation:

Now it will become a job for OS. Now OS will search for its exe file that is stored in secondary storage. If exe found by OS will load the exe into main memory RAM. Then that will become process. After that OS will create a record for process which is called PCB (Process Control Block). Then OS will assign identification to each and every process. Then processes are ready for execution.

PCB (Process Control Block)

Execution:

One process can execute at one time. Then system gives every process time for running which is called time slices. After that one process will dispatch (which mean process will move to ready to running state) and we have three possibilities when a process is in running

  1. If process is complete then it will terminate

  2. If process timeout then it will go back to ready state and wait for running.

  3. If input occurs then process will suspend and will go to block state and wait for user when user will give input then it will resume.

    Terminate

    Dispatch

    Suspend

    Create Timeout

    Resume

It is responsibility of OS to successfully manage these states and apply transition this whole process is called process execution cycle.

Process Management in Detail:

it is the responsibility of OS to successfully execute program.

First OS load the program into main memory then it became process after that OS creates a record of information about that process which is called PCB (Process Control Block). When ready active list is heavily loaded then some of the processes are suspended. So whenever room is available then suspended processes will resume. OS will entertain only active ready list.

PCB active PCB suspended

Terminate

Dispatch

Suspend

Create Timeout

Resume

Resume Suspend

Resume Suspend

So these are basic operation transitions. An action which change state is called transition.

· Dispatch

· Timeout

· Suspend

· Resume

OS will have to maintain these states and apply transition.

It is also called 7 state model.

  1. Create

  2. Ready active

  3. Ready suspended

  4. Running

  5. Terminated

  6. Block active

  7. Block suspended

Different operating system create PCB in different manner but the minimum information that maintained by every operating system like this.

Structure of PCB in C language.

![Text Box: Struct pcb { int PID; char Pname; int UID; Memory menu; Resources req_res; Resources alloc_res; Resources crea_res; PCB parent; PCB progeny; int processor; int priority; char status; Account acc; };

](file:///C:/Users/COMPUT~1/AppData/Local/Temp/msohtmlclip1/01/clip_image030.gif align="left")

PID: So whenever process created operating system will assign a unique identification to each and every process. Operating system recognize process through id not by its name.

Pname: Process name is external name through which process is executed and stored.

UID: In multi user system multiple user can execute process so operating assign each and every user an id. So operating system will recognize the through its process id and user id.

Memory *menu: Lets understand it with when 5 process load In RAM and user close 2 of them so when new program load in RAM it will empty places

Load 5 processes -> 2 process closed ( size of 400b and 300b)

new program loaded of size 700b -> so it half part loaded in 400b place and half part 300b

Now program is loaded in sparse. Then operating system should know about the memory otherwise it operating system will not execute it so for this purpose operating system create a linkedlist first block contain address and second contain the size. It will contain the record of memory that have been occupied by this process.

Resource *req_res; : Operating system is the manager of the resources that share in computing environment. Operating system maintain a list of resources (mean all sharable entities) Whenever process is executed it request different resources at different time.

For example it is list of different resources

  1. Memory

  2. Storage

  3. .

  4. .

  5. .

  6. .

  7. .

  8. .

  9. Sin

  10. Cos

  11. .

  12. ….

And so on

We have operation in process

c = a * sin(30); save (c);

First this operation will request for memory then it will request for sin function and then it will request storage so a linkedlist in which this requested resource information is stored.

Resource *allo_res; : Then resource allocated to that process and a linkedlist created of allocated resource.

Resource *crea_res; : Whenever user has been declared something public in his program these all are added to resources list now anyone can access it. Those resources that are created by this process are called created resource. A linkedlist will be created in which that created resource will store.

PCB *parent; : Lets understand with example

![Text Box: #include void main() { exec(“second.exe”); spawn(“third.h”); }

](file:///C:/Users/COMPUT~1/AppData/Local/Temp/msohtmlclip1/01/clip_image037.gif align="left")

These are valid statements of c. exe is used to execute another program unconditionally. Spawn is used to execute another program conditionally. Now first.c is parent process and second.exe and third.exe are child processes of first.c. So They are dependent processes. Whenever first process is terminate then second and third will also terminated. *parent is pointer to parent process.

PCB *progeny; : first child of parent process is called progeny. *progeny is pointer to first child. That’s why its necessary there should be link to parent to child process.

Processor: In multiprocessor system operating system should know which processor allocate to which process. So processor indicate number of process currently allocate to that processor.

Priority: Order of execution will be called priority of process. Order of execution that is determine by scheduler.

Char *status: its specify the current status of process.

Account acc: its mean accounting record. Relevant information which are not used in execution but used to determine the priority will store in this field.

Process Scheduling:

Process scheduling mean to arrange order of execution of process or assigning priority to each and every process. So we have a scheduling criteria for assigning priority to each and every process.

  1. Processing mode

  2. Parameters

  3. Arbitirarien rule

i. Processing Mode: According to hardware we have two processing mode

  1. Non-Pre emptive

  2. Pre emptive

Non Pre emptive : if process assign to CPU and CPU complete that process without releasing it then this mode is called non pre emptive processing mode. In non pre emptive processing mode there is no time slices. If input output occur processor will wait for it until process complete. When one process complete then other will execute.

Pre emptive: In pre emptive processing mode CPU will release process after its time slice. In pre emptive processing mode scheduling algorithm can be pre emptive or non pre emptiive but in non pre emptive scheduling algorithm will not be pre emptive.

Parameters: Different scheduling algorithm determine priority on the bases of different parameters.

· Arrival time

· Size

· Attained service time

· Total service time

· Real time

· Heavy loaded

· Timeline

Arrival Time: This scheduling algorithm is based on arrival time. It uses arrival time for the calculation of priority. So if some load in main memory at different time, process which come first will execute first.

For example:

Process arrival time

P1 – 11:00

P2 - 11:03

P3 - 11:05

So first p1 will execute because p1 come first and then p2 and p3.

Size: This scheduling algorithm is based on the size. If all process load in the memory at the same time then it will execute shortest first. So size of process used for calculation of priority. There are different algorithm some use purely size as priority determine and some use partially size as priority determine.

For example

Process arrival time -- Size

P1 – 11:00 2kb

P2 - 11:00 1kb

P3 - 11:00 856b

In this case shortest will execute first which is p3 and then p2 and then p1 will execute.

Attained service time: sum of all time slices is called attained service time. So there are scheduling algorithm that based on attained service time. If a process avail more CPU time then its priority will be decrease. If a process not utilize CPU then its priority will be high.

Total service time: Time that has been avail by process for availing different resources is called total service time.

Real time: Real time processes are those that requires imgiid response otherwise that may cause disaster. For example radar is connected with system and you are doing other tasks on system but the basic objective of system is radar. So whenever system detect any obstacle or jet then system will stop all other task and imigidly response to real time process which is in this case signal. If system will not response then it may cause disaster.

Heavy loaded: if system is heavily loaded then some of the processes are suspended and system will give high priority to active processes.

PCB active PCB suspended

Timeline: There are some processes which are time based processes. So time based processes are always executed at fix time.

Aribitrarin Rule: There is always possibility that there may be collision in priority. Each and every operating system have mechanism to break the collision of priority and that mechanism is called aribitrarin rule.

Algorithms:

Non Pre emptive:

· FCFS

· SJF

FCFS: ( it means first come first serve) the efficiency of algorithm are compared in the form of average response time and average wait time. According to criteria the process will come first will execute first.

Response Time: Response time is total completion time.

Wait Time: A process waited before its start time is wait time.

Burst time: Time required for process is called burst time.

Completion time – Arrival time = Response time

Start time – Arrival time = Burst time

Processes

Arrival time

Burst time

Response time

Wait time

P1

0

6

6

0

P2

1

3

8

5

P3

2

4

11

7

P4

3

1

11

10

P5

4

2

12

10

48/5 = 9.6 32/5 = 6.4

Timeline

P1

P2

P3

P4

P5

0 6 9 13 14 16

SJF: ( shortest job first):

First of all first process will execute and then shortest will execute first. The process which require less time for execution will be executed first.

Processes

Arrival time

Burst time

Response time

Wait time

P1

0

6

6

0

P2

1

3

8

5

P3

2

4

11

7

P4

3

1

11

10

P5

4

2

12

10

40/5 = 8 24/5 = 4.8

Timeline

P1

P4

P5

P2

P3

0 6 7 9 12 16

Each and every algorithm compared with its average response time and average wait time if the response time will same then it will compare on average wait time. It is not necessary that one algorithm that is better in one situation will always better in all situations.