Test Book

OPERATING SYSTEM

An operating system (OS) is a collection of software that manages computer hardware resources and provides common services for computer programs. The operating system is a vital component of the system software in a computer system.

An operating System (OS) is an intermediary between users and computer hardware. It provides users an environment in which a user can execute programs conveniently and efficiently.

In technical terms, It is a software which manages hardware. An operating System controls the allocation of resources and services such as memory, processors, devices and information.

Definition

An operating system is a program that acts as an interface between the user and the computer hardware and controls the execution of all kinds of programs.

Conceptual view of an Operating System

Following are some of important functions of an operating System.

  • Memory Management
  • Processor Management
  • Device Management
  • File Management
  • Security
  • Control over system performance
  • Job accounting
  • Error detecting aids
  • Coordination between other software and users

Memory Management

Memory management refers to management of Primary Memory or Main Memory. Main memory is a large array of words or bytes where each word or byte has its own address.

Main memory provides a fast storage that can be access directly by the CPU. So for a program to be executed, it must in the main memory. Operating System does the following activities for memory management.

  • Keeps tracks of primary memory i.e. what part of it are in use by whom, what part are not in use.
  • In multiprogramming, OS decides which process will get memory when and how much.
  • Allocates the memory when the process requests it to do so.
  • De-allocates the memory when the process no longer needs it or has been terminated.

Processor Management

In multiprogramming environment, OS decides which process gets the processor when and how much time. This function is called process scheduling. Operating System does the following activities for processor management.

  • Keeps tracks of processor and status of process. Program responsible for this task is known as traffic controller.
  • Allocates the processor(CPU) to a process.
  • De-allocates processor when processor is no longer required.

Device Management

OS manages device communication via their respective drivers. Operating System does the following activities for device management.

  • Keeps tracks of all devices. Program responsible for this task is known as the I/O controller.
  • Decides which process gets the device when and for how much time.
  • Allocates the device in the efficient way.
  • De-allocates devices.

File Management

A file system is normally organized into directories for easy navigation and usage. These directories may contain files and other directions. Operating System does the following activities for file management.

  • Keeps track of information, location, uses, status etc. The collective facilities are often known as file system.
  • Decides who gets the resources.
  • Allocates the resources.
  • De-allocates the resources.

Other Important Activities

Following are some of the important activities that Operating System does.

  • Security -- By means of password and similar other techniques, preventing unauthorized access to programs and data.
  • Control over system performance -- Recording delays between request for a service and response from the system.
  • Job accounting -- Keeping track of time and resources used by various jobs and users.
  • Error detecting aids -- Production of dumps, traces, error messages and other debugging and error detecting aids.
  • Coordination between other softwares and users -- Coordination and assignment of compilers, interpreters, assemblers and other software to the various users of the computer systems.

Operating systems are there from the very first computer generation. Operating systems keep evolving over the period of time. Following are few of the important types of operating system which are most commonly used.

Batch operating system

The users of batch operating system do not interact with the computer directly. Each user prepares his job on an off-line device like punch cards and submits it to the computer operator. To speed up processing, jobs with similar needs are batched together and run as a group. Thus, the programmers left their programs with the operator. The operator then sorts programs into batches with similar requirements.

The problems with Batch Systems are following.

  • Lack of interaction between the user and job.
  • CPU is often idle, because the speeds of the mechanical I/O devices is slower than CPU.
  • Difficult to provide the desired priority.

Time-sharing operating systems

Time sharing is a technique which enables many people, located at various terminals, to use a particular computer system at the same time. Time-sharing or multitasking is a logical extension of multiprogramming. Processor's time which is shared among multiple users simultaneously is termed as time-sharing. The main difference between Multiprogrammed Batch Systems and Time-Sharing Systems is that in case of Multiprogrammed batch systems, objective is to maximize processor use, whereas in Time-Sharing Systems objective is to minimize response time.

Multiple jobs are executed by the CPU by switching between them, but the switches occur so frequently. Thus, the user can receives an immediate response. For example, in a transaction processing, processor execute each user program in a short burst or quantum of computation. That is if n users are present, each user can get time quantum. When the user submits the command, the response time is in few seconds at most.

Operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of a time. Computer systems that were designed primarily as batch systems have been modified to time-sharing systems.

Advantages of Timesharing operating systems are following

  • Provide advantage of quick response.
  • Avoids duplication of software.
  • Reduces CPU idle time.

Disadvantages of Timesharing operating systems are following.

  • Problem of reliability.
  • Question of security and integrity of user programs and data.
  • Problem of data communication.

Distributed operating System

Distributed systems use multiple central processors to serve multiple real time application and multiple users. Data processing jobs are distributed among the processors accordingly to which one can perform each job most efficiently.

The processors communicate with one another through various communication lines (such as high-speed buses or telephone lines). These are referred as loosely coupled systems or distributed systems. Processors in a distributed system may vary in size and function. These processors are referred as sites, nodes, computers and so on.

The advantages of distributed systems are following.

  • With resource sharing facility user at one site may be able to use the resources available at another.
  • Speedup the exchange of data with one another via electronic mail.
  • If one site fails in a distributed system, the remaining sites can potentially continue operating.
  • Better service to the customers.
  • Reduction of the load on the host computer.
  • Reduction of delays in data processing.

Network operating System

Network Operating System runs on a server and and provides server the capability to manage data, users, groups, security, applications, and other networking functions. The primary purpose of the network operating system is to allow shared file and printer access among multiple computers in a network, typically a local area network (LAN), a private network or to other networks. Examples of network operating systems are Microsoft Windows Server 2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.

The advantages of network operating systems are following.

  • Centralized servers are highly stable.
  • Security is server managed.
  • Upgrades to new technologies and hardwares can be easily integrated into the system.
  • Remote access to servers is possible from different locations and types of systems.

The disadvantages of network operating systems are following.

  • High cost of buying and running a server.
  • Dependency on a central location for most operations.
  • Regular maintenance and updates are required.

Real Time operating System

Real time system is defines as a data processing system in which the time interval required to process and respond to inputs is so small that it controls the environment. Real time processing is always on line whereas on line system need not be real time. The time taken by the system to respond to an input and display of required updated information is termed as response time. So in this method response time is very less as compared to the online processing.

Real-time systems are used when there are rigid time requirements on the operation of a processor or the flow of data and real-time systems can be used as a control device in a dedicated application. Real-time operating system has well-defined, fixed time constraints otherwise system will fail.For example Scientific experiments, medical imaging systems, industrial control systems, weapon systems, robots, and home-applicance controllers, Air traffic control system etc.

There are two types of real-time operating systems.

Hard real-time systems

Hard real-time systems guarantee that critical tasks complete on time. In hard real-time systems secondary storage is limited or missing with data stored in ROM. In these systems virtual memory is almost never found.

Soft real-time systems

Soft real time systems are less restrictive. Critical real-time task gets priority over other tasks and retains the priority until it completes. Soft real-time systems have limited utility than hard real-time systems. For example, Multimedia, virtual reality, Advanced Scientific Projects like undersea exploration and planetary rovers etc.

An Operating System provides services to both the users and to the programs.

  • It provides programs, an environment to execute.
  • It provides users, services to execute the programs in a convenient manner.

Following are few common services provided by operating systems.

  • Program execution
  • I/O operations
  • File System manipulation
  • Communication
  • Error Detection
  • Resource Allocation
  • Protection

Program execution

Operating system handles many kinds of activities from user programs to system programs like printer spooler, name servers, file server etc. Each of these activities is encapsulated as a process.

A process includes the complete execution context (code to execute, data to manipulate, registers, OS resources in use). Following are the major activities of an operating system with respect to program management.

  • Loads a program into memory.
  • Executes the program.
  • Handles program's execution.
  • Provides a mechanism for process synchronization.
  • Provides a mechanism for process communication.
  • Provides a mechanism for deadlock handling.

I/O Operation

I/O subsystem comprised of I/O devices and their corresponding driver software. Drivers hides the peculiarities of specific hardware devices from the user as the device driver knows the peculiarities of the specific device.

Operating System manages the communication between user and device drivers. Following are the major activities of an operating system with respect to I/O Operation.

  • I/O operation means read or write operation with any file or any specific I/O device.
  • Program may require any I/O device while running.
  • Operating system provides the access to the required I/O device when required.

File system manipulation

A file represents a collection of related information. Computer can store files on the disk (secondary storage), for long term storage purpose. Few examples of storage media are magnetic tape, magnetic disk and optical disk drives like CD, DVD. Each of these media has its own properties like speed, capacity, data transfer rate and data access methods.

A file system is normally organized into directories for easy navigation and usage. These directories may contain files and other directions. Following are the major activities of an operating system with respect to file management.

  • Program needs to read a file or write a file.
  • The operating system gives the permission to the program for operation on file.
  • Permission varies from read-only, read-write, denied and so on.
  • Operating System provides an interface to the user to create/delete files.
  • Operating System provides an interface to the user to create/delete directories.
  • Operating System provides an interface to create the backup of file system.

Communication

In case of distributed systems which are a collection of processors that do not share memory, peripheral devices, or a clock, operating system manages communications between processes. Multiple processes with one another through communication lines in the network.

OS handles routing and connection strategies, and the problems of contention and security. Following are the major activities of an operating system with respect to communication.

  • Two processes often require data to be transferred between them.
  • The both processes can be on the one computer or on different computer but are connected through computer network.
  • Communication may be implemented by two methods either by Shared Memory or by Message Passing.

Error handling

Error can occur anytime and anywhere. Error may occur in CPU, in I/O devices or in the memory hardware. Following are the major activities of an operating system with respect to error handling.

  • OS constantly remains aware of possible errors.
  • OS takes the appropriate action to ensure correct and consistent computing.

Resource Management

In case of multi-user or multi-tasking environment, resources such as main memory, CPU cycles and files storage are to be allocated to each user or job. Following are the major activities of an operating system with respect to resource management.

  • OS manages all kind of resources using schedulers.
  • CPU scheduling algorithms are used for better utilization of CPU.

Protection

Considering a computer systems having multiple users the concurrent execution of multiple processes, then the various processes must be protected from each another's activities.

Protection refers to mechanism or a way to control the access of programs, processes, or users to the resources defined by a computer systems. Following are the major activities of an operating system with respect to protection.

  • OS ensures that all access to system resources is controlled.
  • OS ensures that external I/O devices are protected from invalid access attempts.
  • OS provides authentication feature for each user by means of a password.

Following are few of very important tasks that Operating System handles

Batch processing

Batch processing is a technique in which Operating System collects one programs and data together in a batch before processing starts. Operating system does the following activities related to batch processing.

  • OS defines a job which has predefined sequence of commands, programs and data as a single unit.
  • OS keeps a number a jobs in memory and executes them without any manual information.
  • Jobs are processed in the order of submission i.e first come first served fashion.
  • When job completes its execution, its memory is released and the output for the job gets copied into an output spool for later printing or processing.

Batch Processing

Advantages

  • Batch processing takes much of the work of the operator to the computer.
  • Increased performance as a new job get started as soon as the previous job finished without any manual intervention.

Disadvantages

  • Difficult to debug program.
  • A job could enter an infinite loop.
  • Due to lack of protection scheme, one batch job can affect pending jobs.

Multitasking

Multitasking refers to term where multiple jobs are executed by the CPU simultaneously by switching between them.Switches occur so frequently that the users may interact with each program while it is running. Operating system does the following activities related to multitasking.

  • The user gives instructions to the operating system or to a program directly, and receives an immediate response.
  • Operating System handles multitasking in the way that it can handle multiple operations / executes multiple programs at a time.
  • Multitasking Operating Systems are also known as Time-sharing systems.
  • These Operating Systems were developed to provide interactive use of a computer system at a reasonable cost.
  • A time-shared operating system uses concept of CPU scheduling and multiprogramming to provide each user with a small portion of a time-shared CPU.
  • Each user has at least one separate program in memory.

Multitasking

  • A program that is loaded into memory and is executing is commonly referred to as a process.
  • When a process executes, it typically executes for only a very short time before it either finishes or needs to perform I/O.
  • Since interactive I/O typically runs at people speeds, it may take a long time to completed. During this time a CPU can be utilized by another process.
  • Operating system allows the users to share the computer simultaneously. Since each action or command in a time-shared system tends to be short, only a little CPU time is needed for each user.
  • As the system switches CPU rapidly from one user/program to the next, each user is given the impression that he/she has his/her own CPU, whereas actually one CPU is being shared among many users.

Multiprogramming

When two or more programs are residing in memory at the same time, then sharing the processor is referred to the multiprogramming. Multiprogramming assumes a single shared processor. Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has one to execute.

Following figure shows the memory layout for a multiprogramming system.

Memory layout

Operating system does the following activities related to multiprogramming.

  • The operating system keeps several jobs in memory at a time.
  • This set of jobs is a subset of the jobs kept in the job pool.
  • The operating system picks and begins to execute one of the job in the memory.
  • Multiprogramming operating system monitors the state of all active programs and system resources using memory management programs to ensures that the CPU is never idle unless there are no jobs

Advantages

  • High and efficient CPU utilization.
  • User feels that many programs are allotted CPU almost simultaneously.

Disadvantages

  • CPU scheduling is required.
  • To accommodate many jobs in memory, memory management is required.

Interactivity

Interactivity refers that a User is capable to interact with computer system. Operating system does the following activities related to interactivity.

  • OS provides user an interface to interact with system.
  • OS managers input devices to take inputs from the user. For example, keyboard.
  • OS manages output devices to show outputs to the user. For example, Monitor.
  • OS Response time needs to be short since the user submits and waits for the result.

Real Time System

Real time systems represents are usually dedicated, embedded systems. Operating system does the following activities related to real time system activity.

  • In such systems, Operating Systems typically read from and react to sensor data.
  • The Operating system must guarantee response to events within fixed periods of time to ensure correct performance.

Distributed Environment

Distributed environment refers to multiple independent CPUs or processors in a computer system. Operating system does the following activities related to distributed environment.

  • OS Distributes computation logics among several physical processors.
  • The processors do not share memory or a clock.
  • Instead, each processor has its own local memory.
  • OS manages the communications between the processors. They communicate with each other through various communication lines.

Spooling

Spooling is an acronym for simultaneous peripheral operations on line. Spooling refers to putting data of various I/O jobs in a buffer. This buffer is a special area in memory or hard disk which is accessible to I/O devices. Operating system does the following activites related to distributed environment.

  • OS handles I/O device data spooling as devices have different data access rates.
  • OS maintains the spooling buffer which provides a waiting station where data can rest while the slower device catches up.
  • OS maintains parallel computation because of spooling process as a computer can perform I/O in parallel fashion. It becomes possible to have the computer read data from a tape, write data to disk and to write out to a tape printer while it is doing its computing task.

Spooling

Advantages

  • The spooling operation uses a disk as a very large buffer.
  • Spooling is capable of overlapping I/O operation for one job with processor operations for another job.

Process

A process is a program in execution. The execution of a process must progress in a sequential fashion. Definition of process is following.

  • A process is defined as an entity which represents the basic unit of work to be implemented in the system.

Components of process are following.

S.N. Component & Description
1 Object ProgramCode to be executed.
2 DataData to be used for executing the program.
3 ResourcesWhile executing the program, it may require some resources.
4 StatusVerifies the status of the process execution.A process can run to completion only when all requested resources have been allocated to the process. Two or more processes could be executing the same program, each using their own data and resources.

Program

A program by itself is not a process. It is a static entity made up of program statement while process is a dynamic entity. Program contains the instructions to be executed by processor.

A program takes a space at single place in main memory and continues to stay there. A program does not perform any action by itself.

Process States

As a process executes, it changes state. The state of a process is defined as the current activity of the process.

Process can have one of the following five states at a time.

S.N. State & Description
1 NewThe process is being created.
2 ReadyThe process is waiting to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by the operating system so that they can run.
3 RunningProcess instructions are being executed (i.e. The process that is currently being executed).
4 WaitingThe process is waiting for some event to occur (such as the completion of an I/O operation).
5 TerminatedThe process has finished execution.

Process States

Process Control Block, PCB

Each process is represented in the operating system by a process control block (PCB) also called a task control block. PCB is the data structure used by the operating system. Operating system groups all information that needs about particular process.

PCB contains many pieces of information associated with a specific process which are described below.

S.N. Information & Description
1 PointerPointer points to another process control block. Pointer is used for maintaining the scheduling list.
2 Process StateProcess state may be new, ready, running, waiting and so on.
3 Program CounterProgram Counter indicates the address of the next instruction to be executed for this process.
4 CPU registersCPU registers include general purpose register, stack pointers, index registers and accumulators etc. number of register and type of register totally depends upon the computer architecture.
5 Memory management informationThis information may include the value of base and limit registers, the page tables, or the segment tables depending on the memory system used by the operating system.This information is useful for deallocating the memory when the process terminates.
6 Accounting informationThis information includes the amount of CPU and real time used, time limits, job or process numbers, account numbers etc.

Process Control Block

Process control block includes CPU scheduling, I/O resource management, file management information etc.. The PCB serves as the repository for any information which can vary from process to process. Loader/linker sets flags and registers when a process is created. If that process get suspended, the contents of the registers are saved on a stack and the pointer to the particular stack frame is stored in the PCB. By this technique, the hardware state can be restored so that the process can be scheduled to run again.

Definition

The process scheduling is the activity of the process manager that handles the removal of the running process from the CPU and the selection of another process on the basis of a particular strategy.

Process scheduling is an essential part of a Multiprogramming operating system. Such operating systems allow more than one process to be loaded into the executable memory at a time and loaded process shares the CPU using time multiplexing.

Scheduling Queues

Scheduling queues refers to queues of processes or devices. When the process enters into the system, then this process is put into a job queue. This queue consists of all processes in the system. The operating system also maintains other queues such as device queue. Device queue is a queue for which multiple processes are waiting for a particular I/O device. Each device has its own device queue.

This figure shows the queuing diagram of process scheduling.

  • Queue is represented by rectangular box.
  • The circles represent the resources that serve the queues.
  • The arrows indicate the process flow in the system.

Queuing Diagram

Queues are of two types

  • Ready queue
  • Device queue

A newly arrived process is put in the ready queue. Processes waits in ready queue for allocating the CPU. Once the CPU is assigned to a process, then that process will execute. While executing the process, any one of the following events can occur.

  • The process could issue an I/O request and then it would be placed in an I/O queue.
  • The process could create new sub process and will wait for its termination.
  • The process could be removed forcibly from the CPU, as a result of interrupt and put back in the ready queue.

Two State Process Model

Two state process model refers to running and non-running states which are described below.

S.N. State & Description
1 RunningWhen new process is created by Operating System that process enters into the system as in the running state.
2 Not RunningProcesses that are not running are kept in queue, waiting for their turn to execute. Each entry in the queue is a pointer to a particular process. Queue is implemented by using linked list. Use of dispatcher is as follows. When a process is interrupted, that process is transferred in the waiting queue. If the process has completed or aborted, the process is discarded. In either case, the dispatcher then selects a process from the queue to execute.

Schedulers

Schedulers are special system softwares which handles process scheduling in various ways.Their main task is to select the jobs to be submitted into the system and to decide which process to run. Schedulers are of three types

  • Long Term Scheduler
  • Short Term Scheduler
  • Medium Term Scheduler

Long Term Scheduler

It is also called job scheduler. Long term scheduler determines which programs are admitted to the system for processing. Job scheduler selects processes from the queue and loads them into memory for execution. Process loads into the memory for CPU scheduling. The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O bound and processor bound. It also controls the degree of multiprogramming. If the degree of multiprogramming is stable, then the average rate of process creation must be equal to the average departure rate of processes leaving the system.

On some systems, the long term scheduler may not be available or minimal. Time-sharing operating systems have no long term scheduler. When process changes the state from new to ready, then there is use of long term scheduler.

Short Term Scheduler

It is also called CPU scheduler. Main objective is increasing system performance in accordance with the chosen set of criteria. It is the change of ready state to running state of the process. CPU scheduler selects process among the processes that are ready to execute and allocates CPU to one of them.

Short term scheduler also known as dispatcher, execute most frequently and makes the fine grained decision of which process to execute next. Short term scheduler is faster than long term scheduler.

Medium Term Scheduler

Medium term scheduling is part of the swapping. It removes the processes from the memory. It reduces the degree of multiprogramming. The medium term scheduler is in-charge of handling the swapped out-processes.

Medium Term Scheduler

Running process may become suspended if it makes an I/O request. Suspended processes cannot make any progress towards completion. In this condition, to remove the process from memory and make space for other process, the suspended process is moved to the secondary storage. This process is called swapping, and the process is said to be swapped out or rolled out. Swapping may be necessary to improve the process mix.

Comparison between Scheduler

S.N. Long Term Scheduler Short Term Scheduler Medium Term Scheduler
1 It is a job scheduler It is a CPU scheduler It is a process swapping scheduler.
2 Speed is lesser than short term scheduler Speed is fastest among other two Speed is in between both short and long term scheduler.
3 It controls the degree of multiprogramming It provides lesser control over degree of multiprogramming It reduces the degree of multiprogramming.
4 It is almost absent or minimal in time sharing system It is also minimal in time sharing system It is a part of Time sharing systems.
5 It selects processes from pool and loads them into memory for execution It selects those processes which are ready to execute It can re-introduce the process into memory and execution can be continued.

Context Switch

A context switch is the mechanism to store and restore the state or context of a CPU in Process Control block so that a process execution can be resumed from the same point at a later time. Using this technique a context switcher enables multiple processes to share a single CPU. Context switching is an essential part of a multitasking operating system features.

When the scheduler switches the CPU from executing one process to execute another, the context switcher saves the content of all processor registers for the process being removed from the CPU, in its process descriptor. The context of a process is represented in the process control block of a process.

Context switch time is pure overhead. Context switching can significantly affect performance as modern computers have a lot of general and status registers to be saved. Content switching times are highly dependent on hardware support. Context switch requires ( n + m ) bxK time units to save the state of the processor with n general registers, assuming b are the store operations are required to save n and m registers of two process control blocks and each store instruction requires K time units.

Context Switch

Some hardware systems employ two or more sets of processor registers to reduce the amount of context switching time. When the process is switched, the following information is stored.

  • Program Counter
  • Scheduling Information
  • Base and limit register value
  • Currently used register
  • Changed State
  • I/O State
  • Accounting

four major scheduling algorithms here which are following

  • First Come First Serve (FCFS) Scheduling
  • Shortest-Job-First (SJF) Scheduling
  • Priority Scheduling
  • Round Robin(RR) Scheduling
  • Multilevel Queue Scheduling

First Come First Serve (FCFS)

  • Jobs are executed on first come, first serve basis.
  • Easy to understand and implement.
  • Poor in performance as average wait time is high.

First Come First Serve Scheduling Algorithm

Wait time of each process is following

Process Wait Time : Service Time - Arrival Time
P0 0 - 0 = 0
P1 5 - 1 = 4
P2 8 - 2 = 6
P3 16 - 3 = 13

Average Wait Time: (0+4+6+13) / 4 = 5.75

Shortest Job First (SJF)

  • Best approach to minimize waiting time.
  • Impossible to implement
  • Processer should know in advance how much time process will take.

Shortest Job First Scheduling Algorithm

Wait time of each process is following

Process Wait Time : Service Time - Arrival Time
P0 3 - 0 = 3
P1 0 - 0 = 0
P2 16 - 2 = 14
P3 8 - 3 = 5

Average Wait Time: (3+0+14+5) / 4 = 5.50

Priority Based Scheduling

  • Each process is assigned a priority. Process with highest priority is to be executed first and so on.
  • Processes with same priority are executed on first come first serve basis.
  • Priority can be decided based on memory requirements, time requirements or any other resource requirement.

Priority Scheduling Algorithm

Wait time of each process is following

Process Wait Time : Service Time - Arrival Time
P0 9 - 0 = 9
P1 6 - 1 = 5
P2 14 - 2 = 12
P3 0 - 0 = 0

Average Wait Time: (9+5+12+0) / 4 = 6.5

Round Robin Scheduling

  • Each process is provided a fix time to execute called quantum.
  • Once a process is executed for given time period. Process is preempted and other process executes for given time period.
  • Context switching is used to save states of preempted processes.

Round Robin Scheduling Algorithm

Wait time of each process is following

Process Wait Time : Service Time - Arrival Time
P0 (0-0) + (12-3) = 9
P1 (3-1) = 2
P2 (6-2) + (14-9) + (20-17) = 12
P3 (9-3) + (17-12) = 11

Average Wait Time: (9+2+12+11) / 4 = 8.5

Multi Queue Scheduling

  • Multiple queues are maintained for processes.
  • Each queue can have its own scheduling algorithms.
  • Priorities are assigned to each queue.

Multi Queue Scheduling Algorithm

What is Thread?

A thread is a flow of execution through the process code, with its own program counter, system registers and stack. A thread is also called a light weight process. Threads provide a way to improve application performance through parallelism. Threads represent a software approach to improving performance of operating system by reducing the overhead thread is equivalent to a classical process.

Each thread belongs to exactly one process and no thread can exist outside a process. Each thread represents a separate flow of control.Threads have been successfully used in implementing network servers and web server. They also provide a suitable foundation for parallel execution of applications on shared memory multiprocessors. Folowing figure shows the working of the single and multithreaded processes.

Single vs Multithreaded Process

Difference between Process and Thread

S.N. Process Thread
1 Process is heavy weight or resource intensive. Thread is light weight taking lesser resources than a process.
1 Process switching needs interaction with operating system. Thread switching does not need to interact with operating system.
1 In multiple processing environments each process executes the same code but has its own memory and file resources. All threads can share same set of open files, child processes.
1 If one process is blocked then no other process can execute until the first process is unblocked. While one thread is blocked and waiting, second thread in the same task can run.
1 Multiple processes without using threads use more resources. Multiple threaded processes use fewer resources.
1 In multiple processes each process operates independently of the others. One thread can read, write or change another thread's data.

Advantages of Thread

  • Thread minimize context switching time.
  • Use of threads provides concurrency within a process.
  • Efficient communication.
  • Economy- It is more economical to create and context switch threads.
  • Utilization of multiprocessor architectures to a greater scale and efficiency.

Types of Thread

Threads are implemented in following two ways

  • User Level Threads -- User managed threads
  • Kernel Level Threads -- Operating System managed threads acting on kernel, an operating system core.

User Level Threads

In this case, application manages thread management kernel is not aware of the existence of threads. The thread library contains code for creating and destroying threads, for passing message and data between threads, for scheduling thread execution and for saving and restoring thread contexts. The application begins with a single thread and begins running in that thread.

User level thread

Advantages

  • Thread switching does not require Kernel mode privileges.
  • User level thread can run on any operating system.
  • Scheduling can be application specific in the user level thread.
  • User level threads are fast to create and manage.

Disadvantages

  • In a typical operating system, most system calls are blocking.
  • Multithreaded application cannot take advantage of multiprocessing.

Kernel Level Threads

In this case, thread management done by the Kernel. There is no thread management code in the application area. Kernel threads are supported directly by the operating system. Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process.

The Kernel maintains context information for the process as a whole and for individuals threads within the process. Scheduling by the Kernel is done on a thread basis. The Kernel performs thread creation, scheduling and management in Kernel space. Kernel threads are generally slower to create and manage than the user threads.

Advantages

  • Kernel can simultaneously schedule multiple threads from the same process on multiple processes.
  • If one thread in a process is blocked, the Kernel can schedule another thread of the same process.
  • Kernel routines themselves can multithreaded.

Disadvantages

  • Kernel threads are generally slower to create and manage than the user threads.
  • Transfer of control from one thread to another within same process requires a mode switch to the Kernel.

Multithreading Models

Some operating system provide a combined user level thread and Kernel level thread facility. Solaris is a good example of this combined approach. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multithreading models are three types

  • Many to many relationship.
  • Many to one relationship.
  • One to one relationship.

Many to Many Model

In this model, many user level threads multiplexes to the Kernel thread of smaller or equal numbers. The number of Kernel threads may be specific to either a particular application or a particular machine.

Following diagram shows the many to many model. In this model, developers can create as many user threads as necessary and the corresponding Kernel threads can run in parallels on a multiprocessor.

Many to many model

Many to One Model

Many to one model maps many user level threads to one Kernel level thread. Thread management is done in user space. When thread makes a blocking system call, the entire process will be blocked. Only one thread can access the Kernel at a time,so multiple threads are unable to run in parallel on multiprocessors.

If the user level thread libraries are implemented in the operating system in such a way that system does not support them then Kernel threads use the many to one relationship modes.

Many to one model

One to One Model

There is one to one relationship of user level thread to the kernel level thread.This model provides more concurrency than the many to one model. It also another thread to run when a thread makes a blocking system call. It support multiple thread to execute in parallel on microprocessors.

Disadvantage of this model is that creating user thread requires the corresponding Kernel thread. OS/2, windows NT and windows 2000 use one to one relationship model.

One to one model

Difference between User Level & Kernel Level Thread

S.N. User Level Threads Kernel Level Thread
1 User level threads are faster to create and manage. Kernel level threads are slower to create and manage.
2 Implementation is by a thread library at the user level. Operating system supports creation of Kernel threads.
3 User level thread is generic and can run on any operating system. Kernel level thread is specific to the operating system.
4 Multi-threaded application cannot take advantage of multiprocessing. Kernel routines themselves can be multithreaded.

results matching ""

    No results matching ""