Вы находитесь на странице: 1из 6

2

007

Operating System
Process & Threads Concept
This document helps the reader to get adequate knowledge
regarding various aspects of process and threads.

Anirban Banerjee
Education Group
©2007, Education Group
Operating System | Process & Thread Concepts

Operating System

PROCESS & THREAD CONCEPTS

PROCESS

Page 2
Operating System | Process & Thread Concepts

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 –

 User Process

 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 –

 New

 Ready

 Running

 Waiting

 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 –

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

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

Page 3
Operating System | Process & Thread Concepts

 CPU registers (contains information of accumulator, index register, stack


pointer, or different types of general purpose register)

 CPU-Scheduling information (Contains process priority, and other process


parameter)

 Memory Management Information

 Accounting Information

 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 –

 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.)

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

 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

Page 4
Operating System | Process & Thread Concepts

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 –

 Information Sharing (use of shared file)

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

 Modularity

 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 –

 Responsiveness (Web browser – user interact while other threads done


several other things like downloading image item etc)

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

Page 5
Operating System | Process & Thread Concepts

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

 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

 User Thread

 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 –

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

 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.)

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

BIBLIOGRAPHY
Operating System Concept by Silberschatz, Galvin & Gagne.

Page 6

Вам также может понравиться