You are on page 1of 9

Operating System

Process Management: Process, Process Control Block, Process States, Threads, Types of Threads, Multithreading. What is Process ? - A process or task is a portion of a program in some stage of execution. A program can consist of several tasks, each working on their own or as a unit - The Process has been given many definition for instance. o A program in execution. o An Asynchronous activity. o The Entity to which processors are assigned. o The Dispatchable Unit. - Each process that runs in an operating system is assigned a process control block that holds information about the process, such as a unique process ID (a number used to identify the process), the saved state of the process, the process priority and where it is located in memory. - The most frequent used definition of a process is program in execution. And The relation between process and program. Is it is the same beast with different name. When this beast is sleeping it is called program and when it is executing it becomes process. - Process on the other hand includes: o Current values of program counter(PC). o Values of Variable. o Contents of the Processors registers. o The Process stack which contains temporary data. - A process is a sequential program in execution. The components of a process are the following: o o o o The object program to be executed The data on which the program will execute Resources required by the program The status of the process's execution
__ - 1 -___________________________________

Multiprogramming. - Conceptually each process has its own virtual CPU in reality, CPU switches back and forth among processes. This rapid switching back and forth is called Multiprogramming.

Multiprocessing. - A multiprocessing system consists of a number of processors communicating via a bus or a network. - There are a two types of multiprocessing system: o Loosely Coupled. o Tightly Coupled.

- Loosely Couple : This system consist of processors that operate stand-alone. Each processors has its own bus, memory and I/O subsystem and communicates with the other processors using network medium. - Tightly Couple : This system on the other hand that consist of processors through network medium. Tightly couple systems run a single instance of the operating system.

What is Process Management ? - Process management is an integral part of any modern day operating system. The OS must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronization among processes. - The process manager is of the four major parts of the operating system. It implements the process abstraction. It does this by creating a model for the way the process uses CPU and any system resources. - The process manager implements CPU sharing ( called scheduling ), process synchronization mechanisms, and a deadlock strategy. In addition, the process manager implements part of the operating system's protection and security.

__

- 2 -___________________________________

Process Attributes. 1. Process Identification. 2. Process State Information. 3. Process Control Information i. Process State. ii. Program counter. iii. CPU register. iv. Process Number. v. Memory Management Information. 1. Process Identification. - The identifier may be numeric, and for example simply the index of the corresponding entry in the primary process table; otherwise, a mapping must be available to allow the operating system to locate the right entry based on the identifier. - Almost every process is created by another process, its parent process, on behalf of a user. 2. Process State Information. - It consists of the contents of processor registers. - When a process is interrupted, the context of the processor must be saved so that it can be restored when the process resumes execution. Typically the context includes user-visible registers, control and status registers, and stack pointer. 3. Process Control Information - This may include scheduling and state information, data structuring, process privileges, and resource ownerships: Unique identification of the process in order to track "which is which" information. A pointer to parent process. Similarly, a pointer to child process (if it exists). The priority of process (a part of CPU scheduling information). Pointers to locate memory of processes.
__ - 3 -___________________________________

A register save area. The processor it is running on. Pointer Process State Process Number Program Counter Registers Memory Limits List of Open Files PCB Process State : - A State may be any of the 5 states of a process (new, ready, running, waiting, halted). Program Counter : - The counter indicates the address of the next instruction to be executed for this process. CPU Register : - The registers vary in number and type depending on the computer architecture. Along with PC, this state information must be saved when an interrupt occurs, to allow the process to be continued correctly afterward. Process Number: - unique identifier of the process, which is very useful by the O.S Memory Management Information - This information may include value of base and limit register, the page tables or segment tables depending on memory segment used by OS. - In Short we can say that PCB serves as the repository for any information that may vary from process to process. Process States:
Admin New Ready Event Occurs Dispatch Time Out Runnin g Release Exit

Event Wait

__

Blocked -___________________________________ -4

- As a process executes, it changes states. The state of a process is defined in part by the current activity of that process. A process goes through a series of discrete process states. - A Process basically goes through 5 states: o Running : The Process that is currently being executed. o Ready : A Process that is prepared to execute when given the opportunity. o Blocked : A Process that can not execute until some events occur as completion of an I/O operation. o New : A Process that has just been created but yet been admitted to the pool of executable processes by Operating System. Typically a new process has not been loaded into main memory. o Exit : A Process that has been released from the pool of execution processes by the operating system either because it halted or because it aborted for some reason. - Logically, the Running and Ready states are similar. In both the cases the process is willing to run only in case of Ready state. There is temporarily no CPU available for it. - The Blocked state is different from the Running and Ready state is in that process cant run. Even. If CPU is available. Process States Transition : - There are basically 6 possible transitions among above mentioned five states. Transition means change of one state of a process to other state. There are various events, which cause a process to transit from one state to other state.
1)

Transition 1 : It occurs when process discovers that it can not


continue. If running process initiates an I/O operation before its allotted time expire. The running process voluntarily relinquishes
Block (Process Name ) : Running -> Block

2)

Transition 2 : Occurs when the scheduler decides that the running


process has run long enough and it is time to let other process have CPU time.
Time-Run-Out(Process Name) : Running -> Ready __ - 5 -___________________________________

3)

Transition 3 : It Occurs when all other processes have had their share
and it is time for the first process to run again.
Dispatch (Process Name) : Ready -> Running

4)

Transition 4 : It Occurs when the external event for which a process


was waiting happens.
Wake Up (Process Name) : Blocked -> Ready

5)

Transition 5 : It Occurs when process is created.


Admitted ( Process Name): New -> Ready

6)

Transition 6 : It Occurs when the Process has finished execution


Exit ( Process Name ) Running -> Terminated

What is Thread :
-

A thread is a basic unit of CPU utilization. It is also called a lightweight process. A thread is a sequence of instructions within a process. A thread behaves like "a process within a process" but it differs, from a process in that a thread does, not have its own PCB. Usually multiple threads are created within a process Threads are different kind of program executing within process. Processes are programs in execution within kernel. (Why Come) The Process Model as we have seen above it thus far is based on two independent concepts : Resources Groping and Execution. Sometimes it is separate them: this is where threads come in. A Thread has a program counter that keeps track of which instruction to execute next. It has a register, which hold its current working variables. It has a stack, which contains the execution history, with one frame for each procedure called but not yet returned from.

__

- 6 -___________________________________

- Thread consists of the following: Thread ID Program Counter Register Set Stack Code Section Data Section Any operating system resources, which are available to the task. - A thread is a single sequence stream within in a process. Because threads have some of the properties of processes, they are sometimes called lightweight processes. Difference Between Processes and Threads: Similarities : - Like Processes threads share CPU and only one thread active(running) at a time. - Like Processes, threads within a processes, threads within a processes execute sequentially. - Like processes, thread can create children. - And like process, if one thread is blocked, another thread can run. Difference : - Unlike processes, threads are not independent of one another. - Unlike processes, all threads can access every address in the task. - Unlike processes, threads are design to assist one other, note that processes might or might not assist one another because processes may originate from different users. Multithreading : - An operating system is known as multi-threaded when several "tasks" (also known as processes) may be run at the same time. - The applications consist of a sequence of instructions known as "threads". These threads will be alternately active, on standby, suspended or destroyed, according to the priority accorded to them or may be run simultaneously.
__ - 7 -___________________________________

A system is known as pre-emptive when it has a scheduler (also called planner), which, according to priority criteria, allocates the machine time between the various processes requesting it. - The system is called a shared time system when a time quota is allocated to each process by the scheduler. This is the case of multi-user systems which allow several users to use different or similar applications on the same machine at the same time. - the system is then referred to as a "transactional system". To do this, the system allocates a period of time to each user. - There is no protection between threads because. o It is impossible, and o It should not be necessary.
-

Per Process Item Address Space Global Variables Open Files Child Processes Pending Alarms Signals and Signal Handlers Accounting Information States of Thread :

Per Thread Item Program Counter Register Stack State

- Like a traditional process, A thread can be in any one of several states: Running, Blocked, Ready, Terminated. o A Running Thread currently has the CPU and is active. o A Blocked Thread is waiting for some event to unblock it. For,ex.. When a thread performed a system call to read from the keyboard, it is blocked unit input is typed. o A Thread can block waiting for some external event to happen or for some other thread to unblock it. o A ready Thread is scheduled to run and will as soon as its turn comes up. The transition between thread states are the same as the transitions between process states.

__

- 8 -___________________________________

Thread Control Block (TCB) - A thread control block (TCB) stores information private to each thread, and it must contain: o A pointer so that is can be chained into a linked lis. o The values of its stack pointer. o A stack area for local variables and saved register. - A TCB may also contain: o Thread number, type, or name. o Age, or how long this thread has been active. - Priority o Resources that this thread has been granted. - It is important to realize that each thread has its own stack. - Each threads stack contains one frame for each procedure called but not yet returned from. - This frame contains the procedures local variables and the return address to use when the procedure call has finished. - Each thread will generally call different procedure and a thus a different execution history. This is why is thread its own stack.

Kernel

__

- 9 -___________________________________

You might also like