Tuesday, July 15, 2008

Operating System - Process & Thread Concepts

Operating System

Process & Thread Concepts

Process

Overview

Process is program in execution. Process does not mean program code. The program code is a text file which act as a passive entity, which will resides in the disk drives; on the other hand, the process is active entity which will executes. Their are two types of process –

v User Process

v System Process

User Process execute the user program, on the other hand the system processes are handled by the operating system itself.

Process State

As the process executes the states are changing. The states are given below –

v New

v Ready

v Running

v Waiting

v Terminated

As the process executes the process change, its state until it terminates. The states are given below –

New – The process is created

Ready – The process is waiting for the execution

Running – The process is executing

Waiting – The process moves to running to waiting state if there is any interrupt occurs as I/O interrupts etc.

Terminated – The process is terminated

Process Control Block

Process control block (PCB) is the main part of any process. PSB will store the all the necessary information regarding process. The information of the PCB can be different types few of them are –

v Process State (Whether process is in new, ready, running or waiting state)

v Program counter (Contains the address of the next instruction)

v CPU registers (contains information of accumulator, index register, stack pointer, or different types of general purpose register)

v CPU-Scheduling information (Contains process priority, and other process parameter)

v Memory Management Information

v Accounting Information

v I/O Status Information

Scheduling Queue

There are different queue for different purpose, which help process scheduling. The different queues are –

· Job Queue (All the process resides here)

· Ready Queue (Residing in main memory are ready & waiting to execute)

· Device Queue (The process, which switch from running state to waiting state for any interrupt. Every device have their own device queue)

Job Scheduler

The process migrates from different queue to different queue for the entire life cycle. The operating system provides some technique to schedule the different process to maximize CPU utilization. For this reason there are different scheduler are present which help job scheduling. They are –

v Long Term Scheduler or Job Scheduler (Select the process from the job pool and loads them in the memory for the execution. This scheduler executes frequently. It will help to control the degree of multiprogramming.)

v Short Term Scheduler (Select the process form ready queue or that are waiting for execute and allocate them CPU for execution. It runs frequently.)

v Mid Term Scheduler (This will swap any executing process and store them in ready queue for later execution. This is also known as swapping.)

Context Switch

The process mainly uses two different types of resources they are CPU and I/O event. If any process consist of mainly I/O event the CPU utilization will be less and if a process is mainly CPU oriented then the I/O resources are wasted. So for maximize CPU utilization the process should be both CPU and I/O event. To maximize CPU utilization operating system provide Context Switch, in this case the operating system switch the current executing process by storing all the necessary information in the PCB and load the new process PCB. Context switch time is highly dependent upon the hardware. The switching time is nothing but overhead. So to reduce the time it will maximize CPU utilization.

Cooperating Process

The process executes in the operating system either independent process or it may be cooperating process. A process is independent process if it cannot affect another process or another process does not affect it. On the other hand the cooperating process is if it can affect or being affected by another process. For many reason the cooperating process are used they are –

v Information Sharing (use of shared file)

v Computation Speedup (break the task into small subparts and executes parallel)

v Modularity

v Convenience

Threads

Overview

Threads are lightweight process (LWP) which acts as a process. Process creation takes longer time and take more resources are wasted than thread creation. Threads contains thread id, program counter, register set all the necessary information as like as process. For the multithread programming environment, threads are used. In modern days every operating system are multithreaded. Take an example of web browser when user view any web page their may simultaneously work many threads like a thread can be used to download images, other used to translate the HTML file on the other hand another used for network connection. Therefore, this multithreading capability provides user convenience. The main advantage of the thread is they take same memory space as taken by the process. The process can break up into several threads and every thread can simultaneously work.

Benefit

There are many benefits of multithreading application. Few of them are –

v Responsiveness (Web browser – user interact while other threads done several other things like downloading image item etc)

v Resource Sharing (Threads share same resources used by the process)

v Economy (Thread creation is easy and take few resources than process creation)

v Utilization of Multiprocessor Architecture (Threads can simultaneously run in different processor therefore take less time)

Kind of Threads

The threads are mainly classified into two parts they are

v User Thread

v Kernel Thread

The user manages user threads and kernel threads are managed by the operating system itself. User threads are easy to handle, they are implemented over the thread library at user level. This thread library creates, managed, and scheduled the user threads in the user space without intervention of the kernel threads. The drawback is that if kernel is single threaded then any block system call (by user thread) will block every other thread to execute simultaneously. Ex- user thread libraries include POSIX P-threads, Mach C-threads and Solaris 2 UI-threads.

On the other hand, kernel threads are create, managed, scheduled by the operating system itself at the kernel space. The creation & management of kernel threads are slow than the user threads. Ex-Windows NT, Windows 2000, Solaris 2, BeOS etc supports kernel threads.

Multithreading Model

As many system provides both user & kernel threads so their are many multithreading model, they are –

v Many-to-One Model (Many user threads maps into one kernel thread. Suffer from block system call. Ex – Green thread library of Solaris 2.)

v One-to-One Model (Every user threads maps to the single kernel thread. Therefore, every creation of user thread must create kernel thread. Ex – Windows NT, Windows 2000, OS/2 support this kind of model.)

v Many-to-Many Model (The user threads maps to the many kernel level threads. The no. of kernel threads same or less than no. of user threads. Ex – Solaris 2, IRIX, HP-UX support this kind of model)

0 comments: