Thursday, 22 April 2021

PROCESS AND THREAD

 Process:-A process is a program at the time of execution. 

Differences between Process and Program 

        Process                                                                                      Program 

Process is a dynamic object.                                      Program is a static object 

Process is sequence of instruction execution.            Program is a sequence of instructions 

Process loaded in to main memory.                            Program loaded into secondary storage devices.

 Time span of process is limited.                                 Time span of program is unlimited.   

Process is a active entity                                              Program is a passive entity

 Process States:- When a process executed, it changes the state, generally the state of process is determined by the current activity of the process.

 Each process may be in one of the following states: 

1. New : The process is beingcreated.

 2. Running : The process is beingexecuted.

 3. Waiting : The process is waiting for some event tooccur. 

4. Ready : The process is waiting to be assigned to a processor. 

5. Terminated : The Process has finishedexecution. 

Only one process can be running in any processor at any time, But many process may be in ready and waiting states. The ready processes are loaded into a “ready queue”. Diagram of process state 

Uploading: 352521 of 352521 bytes uploaded.



 a) New ->Ready : OS creates process and prepares the process to be executed, then OS moved the process into ready queue.

 b) Ready->Running : OS selects one of the Jobs from ready Queue and move them from ready to Running. 

c) Running->Terminated : When the Execution of a process has Completed, OS terminates that process from running state. Sometimes OS terminates the process for some other reasons including Time exceeded, memory unavailable, access violation, protection Error, I/O failure and soon.

 d) Running->Ready : When the time slot of the processor expired (or) If the processor received any interrupt signal, the OS shifted Running -> Ready State.

 e) Running -> Waiting : A process is put into the waiting state, if the process need an event occur (or) an I/O Device require.

 f) Waiting->Ready : A process in the waiting state is moved to ready state when the event for which it has been Completed.

PCB:- Each process is represented in the operating System by a Process Control Block. It is also called Task Control Block. It contains many pieces of information associated with a specific Process. 

Process State

 Program Counter 

CPU Registers 

CPU Scheduling 

Information Memory – Management Information 

Accounting Information

 I/O Status Information

 1. Process State : The State may be new, ready, running, and waiting, Terminated… 

2. Program Counter : indicates the Address of the next Instruction to be executed.

 3. CPU registers : registers include accumulators, stack pointers, General purpose Registers…. 

4. CPU-Scheduling Info : includes a process pointer, pointers to scheduling Queues, other scheduling parameters etc.

 5. Memory management Info: includes page tables, segmentation tables, value of base and limit registers.

 6. Accounting Information: includes amount of CPU used, time limits, Jobs(or)Process numbers.

 7. I/O Status Information: Includes the list of I/O Devices Allocated to the processes, list of open files.

 Threads: A process is divide into number of light weight process, each light weight process is said to be a Thread. The Thread has a program counter (Keeps track of which instruction to execute next), registers (holds its current working variables), stack (execution History). 

Thread States: 

1. born State : A thread is just created. 

2. ready state : The thread is waiting for CPU. 

3. running : System assigns the processor to the thread.

 4. sleep : A sleeping thread becomes ready after the designated sleep time expires.

 5. dead : The Execution of the threadfinished.

 Eg: Word processor. Typing, Formatting, Spell check, saving are threads. 

Differences between Process and Thread 

                          Process                                                                Thread 

Process takes more time to create.                                       Thread takes less time to create. 

it takes more time to complete execution & terminate.         Less time to terminate.

 Execution is very slow.                                                         Execution is very fast.

 It takes more time to switch b/w two processes.                  It takes less time to switch b/w two threads.

 Communication b/w two processes is difficult .                  Communication b/w two threads is easy.

 Process can’t share the same memory area.                        Threads can share same memory area.

 System calls are requested to communicate each other.      System calls are not required. 

Process is loosely coupled.                                                   Threads are tightly coupled. 

It requires more resources to execute.                                      Requires few resources to execute.

 Multithreading: A process is divided into number of smaller tasks each task is called a Thread. Number of Threads with in a Process execute at a time is called Multithreading. 

1 comment:

My Feelings for death

 Kyu hoti hai kisi ki death, I don't know but why. M aaj tak nhi samjh pae ki ensan ki death kyu hoti hai. Kisi se bhi pucho to ye jawab...