UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types...

67
UNIT-I CHAPTER 1 INTRODUCTION TO OPERATING SYSTEMS TOPICS TO BE COVERED Operating System Definition Operating System Goals Main Function of an Operating System Modes of Operation Classification of Operating Systems Mainframe Systems Simple Batch System SPOOLING (Simultaneous Peripheral Operation Online) Turn around time, Throughput and Response time Multiprogrammed Batch Systems (MBS) Time-Sharing System (TSS) Swapping Desktop Systems Multiprocessor systems (parallel system) Distributed System Clustered systems Real-Time Operating Systems (RTOS) Handheld systems Hardware Protection Common System Components Operating System – Services System Calls System Programs CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E 1

Transcript of UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types...

Page 1: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

UNIT-I

CHAPTER 1

INTRODUCTION TO OPERATING SYSTEMS

TOPICS TO BE COVERED

Operating System Definition

Operating System Goals

Main Function of an Operating System

Modes of Operation

Classification of Operating Systems

Mainframe Systems

Simple Batch System

SPOOLING (Simultaneous Peripheral Operation Online)

Turn around time, Throughput and Response time

Multiprogrammed Batch Systems (MBS)

Time-Sharing System (TSS)

Swapping

Desktop Systems

Multiprocessor systems (parallel system)

Distributed System

Clustered systems

Real-Time Operating Systems (RTOS)

Handheld systems

Hardware Protection

Common System Components

Operating System – Services

System Calls

System Programs

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

1

Page 2: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

1.1 Operating System Definition:

Definition 1: Operating system is a program that acts as an intermediary between user of a computer and the computer hardware.

Definition 2: Operating system provides a convenient platform for the application programs to be developed.

Definition 3: An operating system is similar to a government. The OS provides means for the proper use of the resources of the computer system. Like a government, the OS performs no use full function by itself. It simply provides an environment within which other program can do useful work.

Definition 4: Operating system is a system-software. Software can be categorized as1. System software

Operating system Language translator Utilities

2. Application software

System software the environment on which application software is developed.

Utilities - set of software, which helps in programming. Example: Editor, Linker, Debugger.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

2

Page 3: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Applications software – define the ways in which the system resources are used to solve the computing problems of the users (compilers, database systems, video games, business programs

Definition 5: The operating system is an interface between user and system hardware.

Definition 6: Operating system is a Resource Allocator. CPU time Memory space File storage space Input output devices

Operating system acts as a manager of these resources and allocates them to specific programs and users as necessary for tasks. Since there may be many possibly conflicting requests for the resources, the OS must decide which requests are allocated resources to operate the computer system efficiently and fairly.

Definition 7: An operating system is a control program.

OS programs are divided into Control program and Supervisory program. A control program manages and controls the execution of user program to prevent errors and improper use of the computer system. It is especially concerned with the operations and control of I/O devices.

Definition 8: Operating system is a Middleware.

Definition 9: It is easier to define operating system by what they do than by what they are.

Definition 10: The operating system is the one program running at all times in the computer [kernel], with all else being application programs.

1.2 Operating System Goals

Primary goal - user convenience. Execute user programs and make solving user problems easier.

Secondary goal - efficient operation of computer system. Make the computer system convenient to use.

1.3 Main Function of an Operating System

1.3.1 OS as an extended machine:

The OS program hides the truth about the hardware from the programmer.

It also hides the disk management, file-oriented interface, interrupts, timers, memory management and other low-level features from programmers.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

3

Page 4: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Hence the abstraction offered by the OS is simpler and easier to use the services offered by bare

machine (the hardware).1.3.2 An OS as a Resource Manager

►The OS must keep track of status of each resource, decides which process is to get the resource (how much & when), allocated it, and reclaim it.

►We distinguish between the resource of memory, processor, I/O devices and information because of the inherent differences in their characteristics.

►Viewing OS as a resource manager, each manager does the following.1. Keep track of the resource.2. Enforce policy that determines who gets what, when and how much.3. Allocate the resource.4. Reclaims the resource.

►We have grouped all the programs of the operating system into four resource categories.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

4

Page 5: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Memory management function:

1.Keep track of memory. What parts are in use and by whom? What parts are not in use (called free)?

2.If multiprogramming decide which process gets memory, when it gets and how much.

3.Allocate the memory when the processes request it and the policy of above allows it.

4.Reclaim the memory when the process no longer needs it or has been terminated.

Process management functions:

1.Keep track of the processor & the status of process. Then the program that does this has been called as the traffic controller.

2.Decide who will have a chance to use the processor, the job scheduler chooses from all the jobs submitted to the system and decides which one will be allowed into the system i.e., have any resource assigned to it.

If multiprogramming, decides which process gets the processor, when and how much, this is called the process scheduler.

3.Allocate the processor to a process by setting up necessary hardware registers; this is often called as dispatcher.

4.Reclaim processor when process relinquishes processor usage, terminates or exceeds allowed amount of usage.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

5

Page 6: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Device management function:

1.Keep track of the device, channels, control unites. This is typically called as the I/O traffic controller.

2.Decide what is an efficient way to allocate the device. If it is to be shared then decide who gets it and how much he is to get; this is called I/O scheduling.

3.Allocate the device and initiate the I/O operation.

4.Reclaim the device. In most case the I/O terminates automatically.

Information management function:

1.Keep track of the information, its location, use, status etc these collective facilities are often called as the file systems.

2.Decide who gets use of the information; enforce protection requirements and provide accessing routines.

3.Allocate the resource (information) eg: open a file.

4.Deallocate the resource eg: close a file.

1.4 Modes of Operation

On-line – Banking system, railway reservation system

Batch – Payroll system, examination system

Real-time – Election processing, accounting.

1.5 Classification of Operating Systems

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

6

Page 7: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

1.6 Mainframe Systems

Mainframe computer systems were the first computers used to tackle many commercial and scientific applications – used for bulk data processing. The growth of mainframe systems

1.Simple Batch Systems2.Multiprogrammed Batch Systems3.Time-Sharing Systems

Mainframe Systems were physically enormous machines. The common input devices were card readers and tape drives. The common output devices were line printers, tape drives and card punches. User did not interact directly with the computer system.

The user or the programmer did the following.1. Prepared a job [program + data + control information]2. Submitted it to the computer operator3. Collected the output later after [minutes\hours\days].

The OS in early computers was fairly simple. Major task of such OS was Automatic job sequencing – automatically transfers control from one job to another. First rudimentary operating system

1.6.1 Simple Batch System

To speed up processing and to reduce setup time, jobs with similar needs were batched together. Programmers submitted the jobs to the operator.

Programs were sorted into batches by the operator. Operator runs each batch. Outputs were sent to

respective programmer. Batch OS normally reads a stream of separate jobs with its own control cards that pre-define what the job does. When the job is completed its output is printed.

Disadvantages: No user interaction between the user and the job while in execution. More turnaround time. CPU is often idle. Because the speeds of mechanical I/O devices are much slower then

the electronic devices [processor]. CPU works in microsecond range. Faster card reader-1200 cards/minute, 20cards/second.

Improvements in technology resulted in faster I/O devices. Correspondingly CPU speeds increased even faster. Problem unresolved but exacerbated.

1.6.2 SPOOLING

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

7

Page 8: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Spooling is an acronym for simultaneous peripheral operation on line.

A high-speed device like a disk is interposed between a running program and a low speed device involved with the program in I/O. Rather then cards being read from the card reader directly into memory and then the job being processed, cards are read directly from the card reader and store onto the disk. The location of the card images is recorded in a table kept by the OS.

In-Spool: Reading cards from a card-reader and record them onto a magnetic disk. When the job is executed, the OS satisfies its request for card reader input by reading from the disk.

Out-Spool: When job requests the printer to output a line, that line is copied into a system buffer and is written to the disk. When the job is completed, the output is actually printed.

Disk is used as a virtual card reader. Reading the content of disk of print them on the print is called out spool.

Spooling uses the disk as a huge buffer, reading ahead from the input device, storing output files until output devices are ready.

SPOOLER: The spooler may be reading the input of one job while printing the output of different job. During this time another job may be executed.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

8

Page 9: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Spooling provides an important data structure- job pool. A pool of jobs on the disk allows the OS to select which job to run next. This increases CPU utilization. The most important aspect of job scheduling is the ability to multi-program.

Advantage of spooling:1.Turnaround time is reduced.2.Used for processing data at a remote sites.3.Overlapping of I/O device and CPU reduces the idle time of CPU.4.Independent of CPU, transform of data between I/O devices.5.Keep CPU and I/O devices working at a much higher-rate.

Problem 1.1A payroll program reads monthly attendance details of 1000 employees and prints their payroll. Reading of a card and printing of a line consumes 100 ms each. While a read or write operation on a magnetic disk consumes 10 msec. Salary processing consumes 5 msec of CPU time per employee. Find the following with and without Spooling

1. Program elapsed time 2. CPU idle time

Solution:Without spooling:

Elapsed time =1000*(100+5+100) msec=1000*205msec=205sec

CPU idle time =205-(1000*5 msec)=205-5

=200secWith spooling:

Elapsed time =1000*(10+5+10) msec=1000*25msec=25sec

CPU idle time =25-(1000*5 msec)=25-5msec=20 sec

Comments: Spooling reduces the elapsed time by 88% and it reduces the CPU idle time by 90%.

1.6.3 Turn around time, Throughput and Response time

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

9

Page 10: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

The interval from the time of submission of a process to the time of its completion is known as turnaround time.

Turn around time of a user job is the time since its submission for processing to the time its result becomes available to the user.

Due to spooling the turn-around time of a job processed in BP system includes the following time intervals.

1.Time till a batch is formed.2.Time spent in executing all jobs of the batch.3.Time spent in printing and sorting the results belonging to different jobs.

Turn around time is the sum of periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O.

Throughput: Throughput of a system is the number of programs processed by the system per unit

time.

Response Time►The response time provided to a computational request is the time between the submission

of the computational request by a user and the reporting of its results to the user.

►The response time is the time from the submission of request until the first response is produced.

►The response time is the amount of time it takes to start responding, but not the time that it takes to output that response.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

10

Page 11: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

1.6.4 Multiprogrammed Batch Systems (MBS)

Spooling provides an important data structure- job pool. A pool of jobs on the disk allows the OS to select which job to run next. This increases CPU utilization. The most important aspect of job scheduling is the ability to multi-program.

Function of MBS

The OS keeps several jobs in memory at a time. This set of jobs is a subset of the job kept in the job pool.

Since the number of jobs kept in memory is equivalent to the number of jobs kept in job pool. The OS picks and begins to execute one of the jobs in the memory. The job may wait for some task say an I/O operation to complete.

In a none-multi-programmed system, the CPU would idle. But in multi-programmed OS, the CPU simply switches to another job. When that job needs to wait, the CPU is switched to another job and so on. Eventually, the first job finishes waiting and gets the CPU back.

As long as there is always some job to execute, the CPU never becomes idle.

Multiprogramming is the first instance where the OS makes decisions for the user.

OS Features Needed for Multiprogramming1. Job scheduling – Process scheduling.2. Memory management – the system must allocate the memory to several jobs. 3. CPU scheduling – the system must choose one among several jobs ready to run.4. Disk/device management – Allocation of devices and I/O routine supplied by the

system.

Several jobs are ready to bring into memory, but there is no sufficient place for them. Then the system will choose the jobs to be brought into main memory from the disk. This decision-making situation is called job scheduling.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

11

Page 12: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Several jobs are reads to run at a time in main memory. Some form of memory management is required to make decision on jobs, which is to be run next. This situation is called CPU Scheduling.

Advantages of MBS:1.CPU utilization increased – CPU is always busy.2.Job scheduling / CPU scheduling is possible.3.OS makes decision for the user.

Disadvantages:1.No user interaction with the system.2.Static debugging.3.User should set up control cards.4.Experimentation/modification takes much turnaround time.

1.6.5 Time-Sharing System (TSS)

Time-sharing (multi tasking) is a logical extension to multiprogramming. Multiple jobs are executed by CPU switching between processes.

The user gives instructions to the OS/program directly and receives immediate response. (Keyboard/CRT).

Functions of TSS:

The CPU is switched among several jobs that are kept in memory and on disk (the CPU is allocated to a job only if the job is in memory).

A job swapped in and out of memory to the disk (swapping).

On-line communication (user interaction) between the user and the system is provided. When the operating system finishes the execution of one command, it seeks the next “control statement” from the user’s keyboard.

On-line file system must be available for users to access data and code.

A TSS allows many users to share the computer simultaneously (Multi-user system).

Since each action or command in a TSS tend to be sort, only a little CPU time is needed for each user. As the system switches rapidly from one user to another user, each user is given

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

12

Page 13: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

the impression that the entire system is dedicated to a single user, where as actually only one computer is being shared among many users.

A time shared OS uses CPU scheduling and multiprogramming to provide each user with a small portion of a time-shared computer. Each user has at least one separate program in memory.

Time sharing OS are more complex than the multi-programmed batch OS.1.Several jobs are kept in memory – memory management and protection.2.Response time, Swapping jobs (memory disk) – virtual memory.3.On-line file system – disk management.4.Concurrent execution – CPU scheduling.5.Orderly execution – job synchronization and communications.6.Waiting time – deadlock.

Advantages1.Interactive /hands on /user interaction.2.Immediate response.3.Dynamic debugging.4.Multiple users can use the CPU.5.Reasonable cost.

Disadvantages1.More complex than multi-programmed batch OS.2.Advanced concept arises.

-Memory management -Virtual memory -Disk management-CPU scheduling -Job synchronization-Deadlock

3.Hardware cost is comparatively more.

1.6.6 Swapping

Swapping is technique of temporarily removing inactive programs from the memory of a computer system to provide space for other active processes.

An inactive program is one, which is neither executing on the CPU nor performing an I/O operation.

The programs existing in memory are classified into three categories.

1.Active programs -one active program executes on the CPU while other perform I/O.

2.Programs being swapped out of the memory.

3.Programs being swapped into the memory.CS1252/OS/Unit 1/Introduction to OS,

S.SENTHIL KUMAR.M.E13

Page 14: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Benefits: Use of swapping is feasible in timesharing systems because the TS supervisor can estimate, when a program is likely to be scheduled next.

Disadvantage: Swapping increase the OS overhead, due to the disk I/O involved.

1.7 Desktop Systems Desktop Systems are Personal computers – computer system dedicated to a single user.

Desktop system changed OS goals from maximizing CPU utilization to maximizing user convenience and responsiveness.

These systems adopt technologies developed for larger Operating Systems.

I/O devices – keyboards, mouse, display screens, small printers.

Often individuals have sole use of computer and do not need advanced CPU utilization of protection features. May run several different types of operating systems (Windows, MacOS, UNIX, LINUX).

Hardware cost is sufficiently low.

Examples: PCs running MS-Windows and Apple Macintosh.

1.8 Multiprocessor systems (parallel system)

Advantages:

1.Increased throughput: Amount of work done in unit time or Number of process completed in unit time.

2.Economy of scale: Multiprocessor system can save more money than multiple single processor system.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

14

Page 15: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

3.Increased Reliability: Graceful degradation leads to minimum loss of data or no loss of data. Hence high level of reliability can be achieved.

The ability to continue providing service proportional to the level of surviving hardware is called graceful degradation.

Systems designed for graceful degradation are also called as fail-soft or fault-tolerant systems.

Tandem System: Tandem system uses both hardware and software duplication to ensure continued operation to avoid failure.

Two identical processors connected by a bus, each with its own local memory. One processor acts as primary and the other is backup processor.

Two copies of each process kept in the system one on the primary processor and other on the backup processor.

At fixed checkpoints, state information of each job is copied to backup. If failure is detected, then backup copy is activated.

Disadvantages: Hardware duplication leads to more cost - Expensive.

There are two kinds of multiprocessing.

1) Symmetric multiprocessing.

2) Asymmetric multiprocessing

Symmetric multiprocessing (SMP)

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

15

Page 16: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Each processor runs an identical copy of OS. These copies communicate with one another as needed. Many processes can run at once without performance deterioration.1

Most modern operating systems support SMP

Advantage: Dynamic job and resources sharing.

Disadvantage: Control of I/O over loading.

Example: UNIX for multi-max computer. Sun OS V5 (Solaris 2).

Asymmetric Multiprocessing

Each processor runs an identical copy of OS and each processor is assigned a specific task. Master-salve relationship exists. Master processor schedules and allocates work to slave

processors. More common in extremely large systems.

Advantage: Increased specializations.

Disadvantage: Decreased reliability.

Example: sun OS V4.

IBM mainframe:

- IBM series/1 mini computer as front end;

- Slave processor as back-end

- Main CPU-relieves of overhead of disk scheduling.

1.9 Distributed System

Loosely coupled system – each processor has its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines

Inter-processor communication is established via high-speed buses and telephone lines. Distribute the computation among several physical processors.

From the point of view of a specific processor in a distributed system, the rest of processors and resources are remote, whereas its own resources are local.

1 Worsening performance CS1252/OS/Unit 1/Introduction to OS,

S.SENTHIL KUMAR.M.E16

Page 17: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

The processors in a distributed system vary in size and function. They may include small Ps, workstations, minicomputers & large general-purpose computer systems.

There are two categories of distributed system1) Client-server systems2) Peer-to-peer systems

1.Client-server system - Centralized system acts as server system to satisfy requests generated by client systems.

Computer server systems – Client sends requests and Server sends back results. File server systems – Provides a file system interface where clients can create, update,

read and delete files.

2.Peer-to-peer systems - The processors communicate with one another through various communication lines such as high-speed buses or telephone lines.

Advantages1.Resource sharing: If a number of different sites are connected to one another then a user at

one site may be able to use the resources available at another site i.e. laser printer file etc. Sharing files at remote site Processing distributed data base Printing files at remote site

2.Computation speedup: Concurrent execution: computations can be partitioned into sub-computations.

These sub computations are distributed to different sites and executed concurrently.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

17

Page 18: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Load sharing: One site may be overloaded with jobs. Some of the jobs may be moved to other lightly loaded sites. This movement of jobs is called load sharing.

3.Reliability: If one site fails in a distributed system the remaining sites can continue operating. The failure of a site must be detected by the system and appropriate action may be needed to recover from the failure. Sometimes, the function of the failure site can be taken over by another site. System must ensure correct transfer of functions.

4.Communication: When several sites are connected to one another by communication network, the users can exchange information. The functions like file transfer; login, mail, web browsing and RPCs can be carried out over great distances.

1.10 Clustered systems Clustered systems gather multiple CPUs together to accomplish computational work.

Clustering allows two or more systems to share storage. They are closely linked via LAN networking.

Clustered is usually performed to provide high availability.

Working: A layer of cluster software runs on the cluster nodes. Each node can monitor one or more of others over the LAN. If the monitored machine fails monitoring machine can take the ownership of its storage and restart the applications that were running on the failed machine.

In asymmetric clustering, one machine is in hot standby mode, while other is running the applications. The hot standby host just monitors the active server. If that server fails, the hot standby host becomes the active server.

In symmetric mode, two or more hosts are running applications and they are monitoring each other. Example: Oracle parallel server designed to run on parallel clusters.

Distributed lock manager: Because of the improvements in distributed computing, most systems do not offer general-purpose distributed file systems. Therefore most clusters do no allow shared access to data on the disk. For this, distributed file system must provide access control and locking to the files. This service is called distributed lock manager.

1.11 Real-Time Operating Systems (RTOS)

A system that is used when rigid time requirements have been placed on the operation of a processor is known as real-time systems.

A real-time system has well-defined fixed time constraints. Processing must be done within the defined constraints, otherwise the system will fail.

RTS is a special purpose OS.RTS is used as control device in dedicated applications.

Examples: Air traffic control Systems that control scientific experiments. Military command & control systems.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

18

Page 19: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Weapon systems.

Real-time application: A real time application is an application which requires a “timely” response from the computer system to prevent failures.

Characteristics of RTOS:

1. Determinism: Determinism is concerned with how long an OS delays before acknowledging an interrupt. In RTOS, process requests for service are dictated by external events and timings. RTOS must deterministically satisfy the requests. So RTOS must have enough speed and capacity to handle all the requests.

2. Responsiveness: Responsiveness is concerned with how long after the acknowledgement; it takes an OS to service the interrupt. Response time requirements are critical for real-time systems.

Determinism + Responsiveness = Response-time to external events.

3. User control: In a non-real-time system, the user either has no control over the scheduling function or has broad guidance on the scheduling function. In RTOS the user is allowed to have a fine-grained control over task priority. The user should be able to distinguish between hard and soft tasks.

4. Reliability: RTOS is responding to events and controlling events in real time. Loss or degradation of performance may lead to large financial loss and Major damage to equipments - even loss of life.

5. Fail-soft operation: The ability of a system to fail in such a way as to preserve as much capability and data as possible. RTOS must be designed to respond to various failure modes.

Two types of RTS1.HRTS (Hard Real-Time System)2.SRTS (Soft Real-Time System)

1.HRTS: A RTS that functions correctly only if it returns the correct results within its time constraints, otherwise system will fail; such system is known as HRTS.

HRTS guarantees that critical tasks can be completed on time.

Catastrophy (terrible events) may occur if some deadlines are missed.

Secondary storage limited or absent, data stored in short term memory, or ROM.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

19

Page 20: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Conflicts with time-sharing systems, not supported by general-purpose operating systems

Example:- A gun targeted to a flight.- Military control system.- Nuclear reactor control system.- Chemical power plants control systems.- Jet engine control system.

2.SRTS: A critical real time task gets priority over other tasks and retains that priority until it completes.

If some deadlines are missed Catastrophy (terrible event) will note happen.

Limited utility in industrial control of robotics

Integrate-able with time-share systems

Useful in applications (multimedia, virtual reality) requiring tight response times.

Example : - Virtual Reality.- Multimedia- Advanced scientific projects [undersea exploration].- Planetary rovers.

Less restrictive type of RTS, have more limited utilities than HRTS

Soft real-time functionality – UNIX, Windows NT.

HRTS SRTS1. Uses rigid time requirements with well-

defined time constraints.

2. Process must be completed on time, otherwise system will fail.

3. Supports deadline scheduling.

4. Catastrophy (terrible events) will occur.

5. Conflicts with time-sharing systems, not supported by general-purpose OS.

6. Example: A gun targeted to a flight. System controls scientific

experiments. Weapon system.

1. Less restrictive time constraints.

2. Priority over the tasks retain until it completes.

3. Does not support deadline scheduling.

4. Catastrophy will not occur.

5. Integrate-able with time-share systems.

6. Example: Virtual reality Multimedia

1.12 Handheld systems

Handheld systems include Personal Digital Assistants (PDAs), such as palm pilots or cellular telephones with connectivity to a network such as internet.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

20

Page 21: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Challenges for developers of device[trade-offs]-Limited physical memory [512KB &8MB]-Processor speed and power supply-Small display-small size [5”*3”]-Weight [1/2 pound]

1.13 Hardware Protection

Early computer systems were single user, programmer-operated systems. The programmer operated the computer from the console and they have the complete control over the system. After the development of operating system, this control was given to the OS. Starting with early OS called, resident monitors, the OS began to perform many operations.

- I/O operations - Sharing system resources- Multiprogramming

Sharing system resources requires operating system to ensure that an incorrect program or poorly behaving human cannot cause other programs to execute incorrectly.

So, there are many possibilities to occur errors, that will affect hardware and hence the system has been stopped. Hence hardware protection is needed and is achieved by the following way.

1) Dual–mode operation 2) I/O protection 3) Memory protection and 4) CPU protection.

1. Dual mode operation - To ensure the proper operations of the computer systems, the operating system and all other programs and their data should be protected from any malfunctioning program. At least we need two separate modes of operation.

1.User Mode - tasks executes on behalf of the user.2.Monitor Mode - tasks executed on behalf of the operating system.

A bit called mode bit is added to the computer hardware to indicate the current mode . Monitor (0) and User (1). When an interrupt or fault occurs hardware switches to monitor mode.

Monitor mode also called as Supervisor mode, System mode, Kernel mode and Privileged mode.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

21

Page 22: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

The dual-mode of operation protects the OS from errant users from one another. Protection is accomplished by designing some of the machine instruction as privileged instruction. The operating system allows the privileged instruction to execute only in monitor mode.

2.I/O Protection - A user program may disrupt the normal operation of the system by issuing an illegal I/O instruction. To prevent users from performing illegal I/O operations, we define all I/O instructions as privileged instruction.

To complete an I/O operation the user program can never gain control of the computer in monitor mode. Then I/O protection can be achieved

3.Memory protection - Memory protection must be provided for interrupt vector and interrupt-service routines of the Operating System. To separate each programs memory space base register and limit registers are used.

Base register holds the starting address of the programs memory space. Limit register holds the size of the memory space.

Any attempt to access monitor memory or other user’s memory by a program executing in user mode leads to fatal error. This scheme prevents the user programs modifying program code or data. Hence Memory outside the defined range is protected.

When executing in monitor mode, the operating system has unrestricted access to both monitor and user’s memory. The load instructions for the base and limit registers are privileged instructions.

4.CPU Protection - We must prevent a user program from getting stuck in an infinite loop or not calling system services and never returning the control on CPU to the Operating System.

A timer can be set to interrupt the computer after a specified period. Timer is decremented every clock tick. When timer reaches the value 0, an interrupt occurs.

Timer commonly used to implement time sharing. Timer also used to compute the current time. Load-timer is a privileged instruction. Hence the control on CPU is often returned to the OS. CPU is protected from infinite loop or infinite execution.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

22

Page 23: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

1.14 Common System Components1.Process Management 2.Main Memory Management3.File Management4.I/O System Management5.Secondary Management6.Networking7.Protection System8.Command-Interpreter System

1.Process Management - A process is a program in execution. A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task. The operating system is responsible for the following activities in connection with process management.

Process creation and deletion. Process suspension and resumption. Provision of mechanisms for process synchronization. Provision of mechanisms for process communication.

2.Main Memory Management - Memory is a large array of words or bytes, each with its own address. It is a repository of quickly accessible data shared by the CPU and I/O devices. Main memory is a volatile storage device. It loses its contents in the case of system failure. The operating system is responsible for the following activities in connections with memory management.

Keep track of which parts of memory are currently being used and by whom. Decide which processes to load when memory space becomes available. Allocate and Deallocate memory space as needed.

3.File Management - A file is a collection of related information defined by its creator. Commonly, files represent programs (both source and object forms) and data . The operating system is responsible for the following activities in connections with file management.

File creation and deletion. Directory creation and deletion. Support of primitives for manipulating files and directories. Mapping files onto secondary storage. File backup on stable (nonvolatile) storage media.

4.I/O System Management - OS hides the peculiarities of specific hardware devices from user. I/O system consists of:

A buffer-caching system that includes spooling. A general device-driver interface. Drivers for specific hardware devices.

5.Secondary Management - Since main memory (primary storage) is volatile and too small to accommodate all data and programs permanently, the computer system must provide secondary storage to back up main memory. Most modern computer systems use disks as the principle on-line storage medium, for both programs and data. The operating system is responsible for the following activities in connection with disk management:

Free space management Storage allocation

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

23

Page 24: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Disk scheduling

6.Networking (Distributed Systems) - A distributed system is a collection processors that do not share memory or a clock. Each processor has its own local memory. The processors in the system are connected through a communication network. Communication takes place using a protocol. A distributed system provides user access to various system resources. Access to a shared resource allows:

Computation speed-up. Increased data availability. Enhanced reliability.

7.Protection System – Protection refers to a mechanism for controlling access by programs, processes, or users to both system and user resources. The protection mechanism must:

Distinguish between authorized and unauthorized usage. Specify the controls to be imposed. Provide a means of enforcement.

8.Command-Interpreter System- this is the interface between the user and the OS. Some OS include command interpreter in the kernel. This program some times called as command-line interpreter or shell. Many commands are given to the operating system by control statements which deal with:

Process creation and management I/O handling Secondary-storage management Main-memory management File-system access Protection Networking

The program that reads and interprets control statements is called variously: Command-line interpreter Shell (in UNIX)

Its function is to get and execute the next command statement.

1.15 Operating System – Services

Operating system provides certain services to programs and to the users of those programs. The specific services provided by the OS differ from one OS to another. These OS services are provided for the convenience of the programmer to make the programming task easier.

The Os Services are: 1.Program execution.2.I/O operation.3.Process management.4.Processor management.5.Memory management.6.File system manipulation.7.Communication.8.Error detection.9.Sharing.10. Resource allocation.11. Accounting.12. Protection.13. Security.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

24

Page 25: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

1) Program execution: The system must be able to load a program into memory and to run the program.

2) I/O operation: A running program may require an I/O operation. Therefore the OS must provide a means to do I/O operation.

3) Process management: As the system consists of collection of concurrent processes, the OS needs to perform process management.

4) Processor management: This includes CPU scheduling for Processes.

5) Memory Management: Main memory is usually too small to accommodate all data and programs. Memory should be managed in an efficient manner to improve both CPU utilization and speed of its response to its users.

6) File – System manipulation: Program need to read and write files. Programs also need to create and delete files by name.

7) Communication: In many circumstances, one process needs to exchange information with another process. There are two ways of communication.

Communication between processes that are executing on the same computer. Communication between processes that are executing on different computer system.

Communication may be achieved by shared memory or by message passing.

8) Error detection: Error may occur in the CPU and memory hardware, in I/O devices, and in the user programs. For each type of error the operating system should take appropriate action to ensure correct and consistent computing.

9) Sharing: System with multiple users can gain efficiency by sharing the computer resources among the users.

10) Resource allocations: When multiple users are logged on the system or multiple jobs are running at the same time, resources must be allocated to each of them.

11) Accounting: We want to keep track of which users use how many resources and which kinds of computer resources. Accounting is used for billing or for usage statistics. This is used for researchers to reconfigure the system to improve computing services.

12) Protections: Protection involves ensuring that all access to system resource is controlled. Owners of information stored in a multi-user computer system want to controlled use of that information.

13) Security: Security of the system from outsiders is important. Such security starts with each user to authenticate by means of a username and password to access the resources.

1.16 System Calls

A system call is a method by which a program makes a request to the Operating System.

System call is the interface between the Operating System and its application programs.

System calls provide the interface between a process and the Operating System.

All services that the Operating System provides can be requested through system calls.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

25

Page 26: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

A system call instruction is an instruction that does not execute a specific function in hardware, but instead generates an interrupt that cause the OS to gain control of the processor. Then the OS determines what kind of system call it is and performs the appropriate service for the system caller.

The flows of control during a system call execution.

1.The program executes the system call instruction.

2.The hardware saves the current ia and psw registers in the iia and ipsw registers.

3.The hardware loads a value of 0 into the psw register which puts the machine in system mode with interrupts disabled.

4.The hardware loads the ia register from the system call interrupt vector location. This completes the execution of the system call instruction by the hardware.

5.Instruction execution contains at the beginning of the system call interrupt handler (whose address was in the system call interrupt vector location).

6.The system call handler completes and executes a return from interrupt(rti) instruction. This restores the ia and psw from the iia and ipsw.

7.The process that executed the system call instruction continues at the instruction after the system call.

System calls can be grouped roughly into five major categories.1) Process control2) File management

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

26

Page 27: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

3) Device management4) Information maintenance5) Communication

1) Process control CreateProcess-Create a new process. Exit-terminate the process making the system call. Wait-wait for another process to exit. Fork-create a duplicate of the process making the system call. Execv-run a new program in the process making the system call.

2) File management Open-get ready to read or write a file. Creat-create a new file and open it. Read-read bytes from an open file. Write-write bytes to an openfile. Lseek-change the location in the file of the next read or write. Close-indicate that you are done reading or writing a file. Unlink-remove a file name from a directory. Stat-get information about a file.

3) Device management Request device, release device. Read, write, reposition Get device attributes, set device attributes. Logically attach or detach devices.

4) Information maintenance Get time or date, set time or date. Get system data, set system data. Get process, file or device attributes. Set process, file or device attributes.

5) Communication (Inter Process communications) CrateMessageQueue-create a queue to hold messages. SendMessage-send a message to a message queue. ReceiveMesage-receive a message from a message queue. DestroyMessageQueue-destroy a message queue. Communications can be achieved in two ways.

Message Passing-information is exchanged through an inter-process communication provided by the OS.

Shared Memory-processes use map memory system calls to gain access to regions of memory owned by other process.

1.17 System Programs

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

27

Page 28: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

System program is the environment on which application programs are developed. System programs also known as system software.

System programs provide a convenient environment for the program development and execution.

Categories of system programs1.File management.2.Status information.3.File modification.4.Programming-language support.5.Program loading and execution.6.Communications7.Command interpreter.

1. File management: These programs create, delete, copy, rename, print, dump, list and generally manipulate files and directories.

2. Status information: These programs simply ask the system for the Date Time Amount of available memory or disk space. Number of users.

3.File modification: These programs such as text editors may be available to create and modify the content of files stored on disk or tape.

4.Programming-language support: Compilers, assemblers and interpreters for common programming languages are provided to the users with the Operating System.

5.Program loading and execution: Once a program is assembled or compiled, it must be loaded into memory. The system may provide absolute loaders, relocatable loaders, linkage editors, and overlay loaders. Debugging programs also a kind of system programs.

6.Communications: These programs provide the mechanism for creating virtual connections among processes, users and different computer systems.

7.Command interpreters: The main function of the command interpreter is to get and execute the next user-specified command. These commands can be implemented in two general ways:

The command interpreter itself contains the code to execute the command.

The command interpreter does not understand the command. It merely uses the command to identify a file to be loaded into memory and executed. Example: UNIX commands.

Problems with the design of a command interpreter:

a)As the code to execute a command is a system program, the OS must provide a mechanism for passing parameters from the command interpreter to the system program.

b) The interpretation of the parameters is left up to the programmer of the system program.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

28

Page 29: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

System utilities: Set of software programs which helps in programming is known as utilities. Editor, linker, debugger are examples of system utilities.

Application Programs: Program that solve common problems or perform common operations are called application

programs or application software. Web browsers, word processors, text formatters, spreadsheets, database systems and

statistical analysis packages and games are examples of application software.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

29

Page 30: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

CHAPTER 2

PROCESSES

TOPICS TO BE COVERED

Process Concept

The process states and state transitions

Process Control Block

Context switching

Process Scheduling concepts

Queuing diagram

Sub functions of process scheduling, when an event occurs

Types of schedulers

Long-term scheduler (LTS) – Job scheduler

Short-term scheduler (STS) – CPU-Scheduler

Medium term scheduler (MTS)

Operations on processes

Process Creation

Process termination

Cooperating processes

Inter-Process communication (IPC)

2.1 Process Concept

Process is a Program in execution. Unit of work in Modern OS. OS is a collection of processes.

System process-Executes system codes. User process-Executes user codes.

By switching between processes [System process / user process] the OS makes the computer more productive.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

30

Page 31: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Program: Passive Entity-File existing in secondary storage medium.Process: Active Entity -Program loaded into main memory- Compartmentalized.

Process is Superset of jobs.

Program/process - Logical entityProcessor - Physical entity

Batch system executes jobs. Time Shared Systems has user program/tasks.

Program in execution: At any instant one instruction is executed in sequential fashion.Program Process

Program is a set of instruction code. Process is a program in execution. Program is a file existing in secondary

memory.Process is a program loaded into main

memory. Program is a passive entity. Process is an active entity. Program has static nature. Process has dynamic nature. Program is source code. Process is more than a program code.

The process states and state transitions

Process state describes the nature of current activity in a process. Five different states are there for a Process. They are:

1.New2.Running3.Waiting/Blocked4.Ready5.Terminated/Exit

1.New: The process is being created. A new process has not yet been loaded into main memory.

2.Running: The process is currently being executed /Instructions are being executed.

3.Waiting /Blocked: The process is waiting for some event to occur, such as the completion of an I/O

operation.CS1252/OS/Unit 1/Introduction to OS,

S.SENTHIL KUMAR.M.E31

Page 32: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

A process that cannot execute until some event occurs is in waiting state. So this state is also called as blocked state.

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

A process that is prepared to execute when given the opportunity.

5.Terminated / Exit: The process has finished execution.

A process has been released from the pool of executable processes.

State transition - A state transition for a process is a change in its state. A state transition is caused by the occurrence of some event in the system. The fundamental state transitions for a process are:

1) Ready to running - the process is scheduled. 2) Running to ready - the process is preempted.3) Running to blocked / waiting - the process makes a request which cannot be

satisfied immediately. 4) Running to terminated - the process completes its execution.5) Blocked to running - the request made by then process is satisfied.

Events pertaining to a process - Process state transitions are caused by occurrence of events in the system. A sample list of events is as under.

1.Resources request event: process makes a resource request 2.Resources release event: A resource is released 3.I /O request event: process wishes to start an I /O operation 4.I /O termination event: An I /O operation completes5.Timer interrupts: The system timer indicates end of a time interval 6.Process creation event: A new process is created 7.Process termination event: A process finishes its execution.8.Message sent event: A message is sent by one process to another 9.Message receive event: a message is received by a process

2.3 Process Control Block

PCB is acronym for Process Control Block. It is also called as TCB (Task Control Block).

PCB is a data structure which contains all information for a process, which is used when in controlling its execution.

Each process is represented in the OS by a PCB/TCB.

PCB/TCB is a repository (storehouse / warehouse) of any information associated with a specific process. This information may vary from process to process.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

32

Page 33: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Process state: The state may be new, ready, running or waiting.

Program Counter: It contains the address of the next instruction to be executed for this process.

CPU registers: The registers vary in number and type depending on the computer architecture.AccumulatorIndex RegisterSPGeneral purpose registers

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

33

Page 34: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

CPU scheduling information: This information may include queues and any others scheduling parameters.

Memory management information: This information may include such information as the value of the base and limit registers, the page table/segment table.

Account information: This information includes the amount of CPU and real time used, time limits, account numbers, job/Process numbers & so on.

I/O Status information: This information includes the list of I/O devices allocated to this process, a list of open files & so on.

The information an operating system generally needs to keep about running processes in order to execute them are:

PSW and CPU register information. CPU scheduling information. Memory – measurement information Event information – In blocked state it contains information about the event, for

which the process is waiting. Accounting information I/O status information

2.4 Context switching

When CPU switches from one process to another process, the system must save the state of the old process and load the saved state for the new process. This phenomenon is known as context switching.

A context switch operation stores the execution context of a program executing on the CPU and loads execution context of a new program into the CPU.

Context-switch time is purely overhead - the system does no useful work while switching. Context switching is time dependent on hardware support.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

34

Page 35: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

2.5 Process Scheduling concepts

Scheduling is the activity of determining which service request should be handled next by a server.

Types of processes - There are two types of processes CPU bound and I/O bound processes. CPU bound process spends more time on computation than I/O operation. I/O bound process spends more time on I/O operation than computing.

Various scheduling queues1.Job queue: As the processes enter the system, they are put in the job queue.2.Ready queue: Processes in the main memory that are ready to execute are kept in a

linked list called ready queue.3.Device queue: List of processes that are waiting for a particular I/O device is called a

device queue. Functions of process scheduling

1. Scheduling: select the process to be executed next on the CPU.2. Dispatching: give the control of the CPU to the selected process. 3. Context saves: save the status of a running process when its execution is to be

suspended.

Dispatcher - The dispatcher is the module that gives control of CPU to the process selected by the short-term scheduler (CPU scheduler).

Functions involved in dispatching1.Switching context.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

35

Page 36: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

2.Switching to user mode.3.Jumping to the proper location in the user program to restart that program.

Dispatch latency - The time it takes for the dispatcher to stop one process and start another process running is known as the dispatch latency.

Four events occur related to scheduling1) Arrival: request arrives in the system when a user submits it to the OS.2) Scheduling: The scheduler select one request for serving. The scheduled request

is removed from the list of pending request.3) Preemption: A request is preempted when the server switches to servicing of

another request before completing the request.4) Completion: The processing of a request gets completed.

Degree of multiprogrammingDegree of multiprogramming is the number of jobs residing in memory at any

instant of time.Degree of multiprogramming is the number of jobs in current mix of

running/waiting jobs.

2.6 Queuing diagram

Queuing diagram is the common representation for a process scheduling. Circles represent the resources. Arrows indicate flow of process.

2.7 Sub functions of process scheduling, when an event occurs

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

36

Page 37: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

2.8 Types of schedulers

2.8.1 Long-term scheduler (LTS) – Job scheduler

The Long-term scheduler (LTS) selects process from the pool of jobs and loads them into main memory for execution. LTS Selects which processes should be brought into the ready queue.

There are often more process submitted that can be executed immediately. These processes are spooled to a mass-storage device where they are kept for later execution. The LTS selects process from this pool of jobs and loads them into main memory for execution.

LTS executes less frequently (in seconds, minutes).

LTS control the degree of multiprogramming.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

37

Page 38: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

2.8.1 Short-term scheduler (STS) – CPU-Scheduler

The short-term scheduler selects from among those jobs in memory, which are ready to execute and allocate the CPU to it.

Short-term scheduler also known as CPU-scheduler. STS executes more frequently (in milliseconds) and very fast.

2.8.3 Medium term scheduler (MTS) Used especially with time-sharing systems as an intermediate scheduling level.

Partially run processes are swapped out of (removed from) memory.

The swapped out process are swapped in (reintroduced) later to continue where they left off.

MTS reduces degree of multiprogramming.

Swapping helps in improving the good process mix of I/O bound and CPU bound processes.

MTS helps in memory to be freed up.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

38

Page 39: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

2.9 Operations on processes The processes in the system can execute concurrently and must be created and deleted

dynamically. Therefore OS provides mechanism for process creation and termination.

There are two main operations on processes1.Process creation.2.Process termination.

2.9.1 Process Creation A new process can be created via a create_process system call. Parent process creates child

process, which, in turn create other processes, forming a tree of processes.

In UNIX OS fork( ) and vfork( ) system calls are used to create a new child process.

Actions performed by an os while creating a process 1.Assign process id and priority.2.Allocate memory and other resources to the process.3.Setup the process environment – load its code component in the environment.4.Create a process control block (PCB) for the process and inilialize its fields with

information concerning the process.5.Return the process id to creator of the process.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

39

Page 40: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Parent and child process A process can create several new processes using a create _ process system call. The creating process is called parent process.The new processes that are created are called children of the creating process.

Resource sharing (among processes and sub – processes) - restricting a child process to a subset of parent’s resources prevents any process from overloading the system by creating too many sub-processes. This is the main advantages of resource sharing/ partitioning.

1.A sub-process may obtain the resources directly from the os or it may be constrained to the resources of the parent process.

2.The parent may have to partition its resources among its children.

3.The parent may share some/whole of its resources among several of in children.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

40

Page 41: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Execution of process1.The parent continues to execute concurrently with its children.2.The parent waits until some or all of its children have terminated.

Address space1.The child process is a duplicate of the parent process.2.The child process has a separate program loaded into it.

UNIX examples fork system call creates new process. exec system call used after a fork to replace the process’s memory space with a new

program.

2.9.2 Process termination

A process terminates when it finishes executing its last statement and asks the OS to delete it. A process can be terminated by using the exit system call.

A process can cause the termination of another process via an appropriate system call (abort). This facility can be invoked only by the parent process. Parent may terminate execution of children processes for the following reasons.

1.The child has exceeded in usage of some resources it has been allocated.2.The task assigned to the child is no longer required.3.The parent is executing and the OS does not allow a child to continue after in parent

terminates. All children terminated - cascading termination

2.10 Cooperating processes

Independent process – process that cannot affect or be affected by the execution of another process is called as independent process.

Cooperating process – process that can affect or be affected by the execution of another process is called as cooperating process.

Advantages of process cooperation.a. Information sharing b.Computation speed-upc.Modularityd.Convenience

Paradigm for cooperating processes - producer process produces information that is consumed by a consumer process

Unbounded-buffer places no practical limit on the size of the buffer. Bounded-buffer assumes that there is a fixed buffer size.

2.11 Inter-Process communication (IPC)

IPC is a mechanism to allow processes to communicate and to synchronize their actions with out sharing the same address space.

IPC is particularly useful in a distributed environment where the communicating processes reside on different computers connected with a network.

Four ways processes interact with one another1.Control synchronization.2.Data access synchronization.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

41

Page 42: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

3.Signal.4.Message passing.

1 Control synchronization - Processes need to coordinate their activities with respect to each other such that a process performs a certain action only after some other processes have performed some specification. This is known as control synchronization.

2 Data access synchronization – In concurrent processes a shared data is accessed in a mutually exclusive manner. This is known as data access synchronization.

3 Signals - Signals are used to convey exceptional condition. When a signal is sent to a process, the process interrupts its execution and executes a specified action before resuming.

4 Message passing - Message passing allow processes to communicate with one another without the need to shared data. Processes exchange information through messages. Process can send some data values to another process in a message. The receiving process can copy values from a message into its own variables. The supervisor must ensure correct delivery of messages.

IPC implementation - Various methods for logically implementing a link and the send /receive operation in a message passing system.

1.Direct or Indirect communication.2.Symmetric or Asymmetric communication.3.Automatic or Explicit buffering.4.Send by copy or Send by reference.5.Fixed sized or Variable sized messages.

Naming - Process that want to communicate must have a way to refer to each other known as naming. Naming is of two types.

1.Direct communication.2.Indirect communication

1) Direct communication: With direct communication each process that wants to communicate must explicitly name recipients or sender of the communication.

Send (P, message)-send a message to process P. Receive (Q, message)-receive a message from process Q.

2) Indirect communication: With indirect communication the messages are sent to and received from mailboxes or ports.

Send (A, message) -send a message to mailbox A. Receive (A, message) -receive a message from mailbox A.

Symmetric and asymmetric addressing:

1) Symmetric addressing: The sender and receiver have to name each other to communicate.

Send (P, message) -send a message to process P. Received (Q, message) -receive a message from process Q.

2) Asymmetric addressing: Only the sender names the recipient and the recipient is not required to name the sender.

Send (P, message) - send a message to process P.CS1252/OS/Unit 1/Introduction to OS,

S.SENTHIL KUMAR.M.E42

Page 43: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Received (id, message) - receive a message from any process. The variable id set to the name of process with which communication has taken place.

Properties of link in direct communication: A link is established between every pair of processes that want to communicate. The

processes need to know only each other’s identity to communicate. A link is associated with exactly two processes. Between each pair of processes, there exists only one link. Link may be unidirectional, but is usually bi-directional.

Mailbox: Mailbox is an abstract object, in which messages can be placed by processes and from which messages can be removed.

Different schemes of indirect communication: Or

Properties of a communication link in indirect communication:

1.A link is established between a pair of processes, only if both members of the pair have a shared mailbox.

2.A link may be associated with more than two processes.

3.A process can communicate with some other process via a number of different mailboxes. i.e. many different links may exist between two processes.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

43

Page 44: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

The mechanisms provided by the OS for the mailbox: Os provides mechanism to do the

following.

To create a mailbox. To send and receive messages through the mailbox. To delete a mailbox.

Synchronous and asynchronous message passing: Synchronous and asynchronous message passing is also known as blocking and non-blocking message passing respectively.

Blocking send: The sending process is blocked until the message is received by he receiving process or by the mailbox.

Nonblocking send: The sending process sends the message and resumes operation. Blocking receive: The receiver blocks until a message is available. Nonblocking receive: The receiver retrieves either a valid message or a null.

Buffering in IPC:

A link has some capacity that determines the number of messages that can reside in it temporarily (Known as line capacity).

Queue of messages attached to a link. These messages are exchanged by communicating processes. This is known as buffering. The queues with different capacities available for buffering in IPC:

Zero capacity: The queue has maximum length zero. Thus the link cannot have any messages waiting in it. Sender must wait until the recipient receives the message. Zero capacity case is referred to as “message system with no buffering”.

Bounded capacity: The queue has a finite length”n”.

Unbounded capacity: The queue has potentially infinite length. Thus any number of messages can wait in it. The sender is never delayed.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

44

Page 45: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Nonzero capacity: Automatic buffering.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

45

Page 46: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

UNIT-II

CHAPTER 3Threads

TOPICS TO BE COVERED

Thread - Overview

Process Vs Thread

Single threaded process and a multithreaded process

Two levels of threads

Multithreading models

Threading issues

P-Threads

3.1 Thread - Overview

Thread is flow of control with in a process.

Thread is a basic unit of CPU utilization.

Thread is a Light Weight Process (LWP).

A thread shares with other threads belonging to the same process.

A thread comprise of

- A thread id- PC - Register set - Stack

3.2 Process Vs Thread

Process Thread Heavy weight process. Lightweight process. Unit of Work done in Modern

O.S Unit of CPU utilization.

Process consists of threads. Flow of control with in a process. Context switching is costly. More economical context

switching.

3.3 Single threaded process and a multithreaded process

Single threaded processo A process with utmost one thread of control. o It can perform only one task at a time.

Multithreaded process:

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

46

Page 47: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

A process having two or more threads. It can perform more than on task at a time.

Advantages of multithreaded programming

Responsiveness-increasing responsiveness to the user

Resource sharing-share the memory and resources of the process to which they belong.

Economy-more economical to create and context switch threads.

Utilization of multiprocessor architecture-multi threading on a multi-CPU machine increases concurrency.

3.4 Two levels of threads

There are two levels of threds:1. User threads.2. Kernel threads.

User threads Thread management done by user-level threads library. (Supported above the kernel.)

Thread library supports to create thread scheduling management.

Thread creation and scheduling are done in user space.

Faster to create and manage.

If the kernel is single threaded, the blocking system calls performed by user thread blocks entire process.

Three primary thread libraries: POSIX P-threads Java threads Win32 threads

Kernel threads Supported by the OS kernel.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

47

Page 48: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Kernel performs thread creation, scheduling management.

Thread creation and scheduling are done in kernel space.

Slower to create and manage.

Since kernel is managing threads, when a blocking system call is performed, kernel can schedule another thread in the application to execute.

Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X

User-threads and kernel-threads

User threads Kernel threads

Supported above the kernel. Supported by the OS kernel.

Thread library supports to create thread, scheduling and management.

Kernel performs thread creation, scheduling, and management.

Thread creation and scheduling are done in user space.

Thread creation and scheduling are done in kernel space.

Faster to create and manage. Slower to create and manage.

If the kernel is single threaded, the blocking system calls performed by user thread blocks entire process.

Since kernel is managing threads, when a blocking system call is performed, kernel can schedule another thread in the application to execute.

Examples: POSIX P-threads Java threads Win32 threads

Examples: Windows XP/2000 Solaris Linux

3.5 Multithreading models

Many systems provide support for both user and kernel threads. This leads to different multi threading models.

Many-to-One model: maps many user-level threads to one kernel thread. Only one thread can access the kernel at a time. So multiple threads are unable to run in parallel on multiprocessors. Green threads – a thread library for Solaris 2uses this model.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

48

Page 49: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

One-to-One model: maps each user thread to a kernel thread. Allows multiple threads to run in parallel on multiprocessors. Creating a user thread requires creating a corresponding kernel thread.

Many-to-Many Model: multiplexes many user-level threads to a smaller or equal number of kernel threads. The number of kernel threads is specific either to a particular application or machine.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

49

Page 50: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

3.6 Threading issues

Semantics of fork( ) and exec( )system calls – changes in thread. Some UNIX systems support two versions of fork( ). One duplicates all the threads in that process and another duplicates only the thread that called the fork( ). The exec( ) system call is similar as in processes.

Thread cancellation – Terminating a thread before it has finished. Two general approaches: Asynchronous cancellation terminates the target thread immediately. Deferred cancellation allows the target thread to periodically check if it should be

cancelled by itself.

Signal handling – Signals are used in UNIX systems to notify a process that a particular event has occurred. A signal may be received either synchronously or asynchronously.

A signal handler is used to process signals1.Signal is generated by particular event2.Signal is delivered to a process3.Signal is handled

Options to signals delivery 1. Deliver the signal to the thread to which the signal applies2. Deliver the signal to every thread in the process3. Deliver the signal to certain threads in the process4. Assign a specific thread to receive all signals for the process

Thread pools - Create a number of threads in a pool where they sit and await for work. The advantages of thread pools are:

Usually slightly faster to service a request with an existing thread than waiting to create a new thread.

Allows the number of threads in the application(s) to be bound to the size of the pool.

Thread specific data - Threads belonging to a process share the data of the process. Each thread needs its own copy of certain data in some circumstances. Such data is called thread specific data.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

50

Page 51: UNIT-1€¦  · Web view2.7 Sub functions of process scheduling, when an event occurs. 2.8 Types of schedulers. 2.8.1 Long-term scheduler (LTS) – Job scheduler . The Long-term

Useful when we do not have control over the thread creation process. That is when we are using a thread pool.

Scheduler activations - Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application. Scheduler activations provide upcalls - a communication mechanism from the kernel to the thread library. This communication allows an application to maintain the correct number kernel threads.

3.7 P-Threads

A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization. P-thread is a user-level thread.

API specifies behavior of the thread library not an implementation. The implementation is up to development of the library. The OS designers may implement the specifications any way they wish.

Common in UNIX operating systems (Solaris, Linux, Mac OS X). UNIX based systems such as Solaris 2 support p-threads. Windows OS generally not supporting p-threads.

CS1252/OS/Unit 1/Introduction to OS, S.SENTHIL KUMAR.M.E

51