Operating Systems 4 Class: Save From
Operating Systems 4 Class: Save From
Operating Systems 4 Class: Save From
org/dep-cs
Operating Systems
4th Class
رنا فريد غني. د:استاذ المادة
Lecture 1
Operating Systems
Operating systems are essential part of any computer system.
Therefore, a course in operating systems is an essential part of any
computer science education. The fundamental concepts of operating
systems will be presented in this course.
Computer systems
Operating System
Computer
Hardware
Computer Structure
User View
The user view of computer varies by the interface being used. The
operating systems are designed mostly for ease of use. Others are
designed to maximize resource utilization. Other operating systems are
designed to compromise between individual usability and resource
utilization.
System view
Mainframe systems
Batch systems
In this type of computer systems, the operator batch together jobs with
similar needs and ran through the computer as group.
The operating system was simple and its major task was to transfer
control automatically from one job to the next.
Multiprogrammed systems
The CPU executes multiple jobs by switching among them, but the
switches occurred so frequently the users can interact with each program
while it is running.
A Time_shared operating systems allows many user programs
(processes) to share the computer simultaneously. The CPU executes
multiple jobs by switching among them, but the switches occurred so
frequently the users can interact with each program while it is running.
Desktop systems
Distributed Systems
client-server systems
peer-to-peer systems
Some operating system benefits from ideas of networking and
distributed systems in build network operating system.
Clustered Systems
Real-Time Systems
Special purpose operating system, it is used when there are rigid time
requirements on the operation of a processor or the flow of data, thus it
is often used as a control device in dedicated application.
Real time system need that the processing must be done within the
defined time constraints or the system will fail.
There are two flavours of real time system:
Hard real-time system
Soft real time system
Handheld Systems
Booting:
It is the operation of bringing operating system kernel from the secondary storage
and put it in main storage to execute it in CPU. There is a program bootstrap
which is performing this operation when computer is powered up or rebooted.
1- Initialize all the aspect of the system, from CPU registers to device
controllers to memory contents.
2- Locate and load the operating system kernel into memory then the
operating system starts executing the first process, such as “init” and waits
for some event to occur.
The operating system then waits for some event to occur
Types of events are either software events (system call) or hardware events
(signals from the hardware devices to the CPU through the system bus and known
as an interrupt).
Interrupt vector (IV): it is a fixed locations (an array) in the low memory area (first
100 locations of RAM) of operating system when the interrupt occur the CPU
stops what its doing and transfer execution to a fixed location (IV) contain starting
address of the interrupt service routine(ISR), on completion the CPU resumes the
interrupted computation.
Hardware protection:
when we have single user any error occur to the system then we could
determined that this error must be caused by the user program ,but when we
begin to dealing with spooling ,multiprogramming, and sharing disk to hold many
users data this sharing both improved utilization and increase problems .
Many programming error are detected by the hardware these error are normally
handled by the operating system.
Dual-Mode Operation:
To ensure proper operation, we must protect the operating system and all other
programs and their data from any malfunctioning program.
The approach taken by many operating systems provides hardware support that
allows us to differentiate among various modes of execution.
A bit, called the mode bit is added to the hardware of the computer to indicates
the current mode: monitor (0) or user (1) with mode bit we could distinguish
between a task that is executed on behalf of the operating system , and one that
is executed on behalf of the user.
Memory Protection:
To insure correct operation, we must protect the interrupt vector and interrupt
service routine from modification by a user program. This protection must be
provided by the hardware, we need the ability to determine the range of legal
addresses that the program may access, and to protect the memory outside that
space. We could provided the protection by using two registers a base register
and limit register
Base register hold the smallest legal physical memory address.
CPU Protection:
In addition to protecting I/O and memory we must insure that the operating
system maintains control. We must prevent the user from getting stuck in an
infinite loop or not calling system services, and never returning control to the
operating system. To accomplish this goal, we can use a timer.
Timer can be set to interrupt the computer after a specified period. The period
may be fixed (for example, 1/60 second) or variable (for example, from 1
millisecond to 1 second) A variable timer is generally implemented by a fixed rate
clock and a counter.
We can use the timer to prevent a user program from running too long Simple
technique is to initialize a counter with the mount of time that a program is
allowed to run.
Amore common use of timer is to implement time sharing. In the most case, the
timer could be set to interrupt every N millisecond, where N is the time slice that
each user is allowed to execute before the next user get control of the CPU. The
operating system is invoked to perform housekeeping tasks.
System Components
Many modern computer systems share the goal of supporting the
following components:
Process management
A process can be thought of a program in execution. A process needs
certain resources to accomplish its task. Also the process various
initialization values.
A process is the unit of work in a system. Such a system consists of a
collection of processes, some of which are system processes others are
user processes. All processes execute concurrently by multiplexing the
CPU among them.
The OS responsible for the following activities in connection with
process management:
Creation and deletion both user and system processes.
Suspending and resuming processes.
Providing mechanisms for process synchronization.
Providing mechanisms for process communication.
Providing mechanisms for deadlock handling.
File Management
For convenient use of the computer, the OS provides a uniform logical
view of information storage. The OS abstracts from the physical
properties of its storage device to define the logical storage unit, the file.
A file is acollection of related information defined by its creator. These
files are organized in directories to ease their use.
The OS responsible for the following activities in connection with file
management:
Creating and deleting files.
Creating and deleting directories.
Supporting primitives for manipulating files and directories.
Mapping files onto secondary storage.
Backing up files on stable storage media.
Networking
A distributed system collects physically separate heterogeneous system
into a single coherent system, providing the user with the access to
various resources that the system maintain. Access to a shared resource
allows computation speed up, increase functionality, increase data
arability, and enhance reliability.
Protection System
Protection is any mechanism for controlling the access programs,
processes, or users to the resources defined by the computer system.
This mechanism must provide means for specification of the controls to
be imposed and means for enforcement. Protection can improve
reliability by detecting latent errors at the interfaces between component
subsystems.
System Calls
System calls provide the interface between a process and the operating
system. These calls are generally available as assembly language
instructions and they are usually listed in the various manuals used by
assembly language.
System Programs
System programs provide a convenient environment for program
development and execution. Some of them are simply user interfaces to
system calls others are considerably more complex. They can be divided
into these categories:
File management
Status information
File modification
Programming language support
Program loading and execution
Communications
System Structure
A system as large and complex as a modern operating system must be
engineered carefully if it is to function properly and to be modified
easily. There are three different system structures:
Simple structure
Layered Approach
Microkernal
System Design and Implementation
The problems and steps of system design and implementation are as
follows:
Design Goals
Mechanisms and Policies
Implementation
Processes
In the following lectures we will consider the concepts of
process.
Process Concepts
A process is a program in execution. A process is more than the
program code, which is sometimes known as the text section. It
also includes the current activity, as represented by the value of
the program counter and the contents of the processor's registers.
Process state
The state of a process is defined in part by the current activity of
the process. Each process may be in one of the following states:
New
Running
Waiting
Ready
Terminated
Process Scheduling
A uniprocessor system can have only one running process. If
more processes exist, as in multiprogramming system, there will
be only one process running and the rest must wait until the
CPU is free and can be rescheduled.
Scheduling Queues
A new process as enter the system is put in a queue called ready
queue. It waits in the ready queue until it is selected for
execution. Once the process is assigned to the CPU and it is
executing, one of the several event could occur:
The process could issue an I/O request, and then be placed in an
I/O queue.
The process could create a new subprocess and wait for the
termination.
The process could be removed forcibly from the CPU, as a
result of an interrupt and be put back in the ready queue.
Scheduler
A process migrates between the various scheduling queues
throughout its lifetime. The operating system must select
processes from these queues in some fashion. The selection
process is carried out by the appropriate scheduler. There are
two types of scheduling algorithms categorized according to the
frequency of their execution.
Long term scheduler (job scheduler) which selects a
process from the job pool and load them into the MM.
Short term scheduler (CPU scheduler) which select a
process from the ready queue and allocate it to the CPU.
Context Switch
Switching the CPU to another process requires saving the state
of the old process and loading the saved state for the process.
This task is known as a context switch.
Operation on Processes
The process in the system can execute concurrently, and they
must be created and deleted dynamically.
Process Creation
A process may create several new processes during the course of
execution. The creating process is called a parent process,
whereas the new processes are called the children.
When a process is created it obtains various resources and
initialization values that may be passed along from the parent
process to the child process.
Process Termination
A process terminates when it finishes executing its final
statement and asks the operating system to delete it. At that
point the process may return data to its parent process and the
OS deallocate all the physical and logical resources that are
previously allocated to that process.
Cooperating Processes
The concurrent process executing in the operating system may
be either independent processes that does not share any data or
cooperating that affects each others.
We may provide an environment that allows process
cooperation for several reasons:
Information sharing
Computation speedup
Modularity
Convenience
Interprocess Communication
The cooperating processes can communicate in a shared
memory environment. The scheme requires that these processes
share a common buffer pool. Another way to achieve the same
effect for the operating system is provided via an interprocess
communication (IPC).
IPC provides a mechanism to allow processes to communicate
and synchronize their actions without sharing the same address
space. This technique is useful for distributed systems. IPC is
provided by a message passing system.
CPU Scheduling
In the following lectures we will introduce the basic scheduling
concepts and present several different CPU scheduling
algorithms.
Scheduling Concepts
Scheduling is a fundamental operating system function. Almost
all computer resources are scheduled before use. The CPU
scheduling is central to operating systems.
CPU Scheduler
Whenever the CPU becomes idle, the operating system must
select one of the processes in the ready queue to be executed.
The selection process is carried out by the short term
scheduler(CPU scheduler). The scheduler selects from among
the processes in in memory that are ready to execute and
allocates the CPU to one of them.
Scheduling Schemes
There are two scheduling schemes can be recognized:
Preemptive scheduling
Nonpreemptive scheduling
Under the nonpreemptive scheduling, once the CPU has been
allocated to a process, the process keeps the CPU until it release
the CPU either by terminating or by switching to the waiting
state. On the other hand Preemptive scheduling occure when the
CPU has been allocted to a process and this process is
interrupted by higher priority process. At this moment the
executing process is stopped and returned back to the ready
queue, the CPU is allocated to the higher priority process.
Dispatcher
It is the module that gives control of the CPU to the process
selected by the CPU scheduler. This function involves:
Switching Context
Switching to user mode
Jumping to the proper location in the user program to
restart the program.
Scheduling Criteria
Many criteria have been suggested for comparing CPU
scheduling algorithms. The criteria include the following:
CPU Utilization
Throughput
Turnedaround Time
Waiting time
Response time
Scheduling Algorithm
Here we will mention soime of the CPU scheduling algorithms
that are used in different operating systems
If the processes arrive in the order P2, P3, P1 the result will be
shown in the following Gantt Chart:
P2 P3 P1
0 3 6 30
Thus the average waiting time under FCFS policy is not the
minimal.
Shortest Job First Scheduling (SJF)
This algorithm associate with each process the length of the
latter's next CPU burst. When the CPU is available, it is
assigned to the process has the smallest next CPU burst. If two
processes have the same length , FCFS scheduling is used to
break this tie.
As an example consider the following set of processes with the
length of the CPU burst given in millisecond:
The average waiting time in SJF is the optimal that it gives the
minimum average waiting time.
The SJF is either preemptive or nonpreemptive. The choice
arises when a new process arrives at the ready queue while a
previous process is executing. The new process may have a
shorter next CPU burst than what is left of the currently
executing process. A preemptive SJF will preempt the currently
executing process whereas a nonpreemptive SJF algorithm will
allow the currently running process to finish its CPU burst.
As an example consider the following set of processes with the
length of the CPU burst given in millisecond: