Anda di halaman 1dari 40

Operating System (CS 3009)

KALINGA INSTITUTE OF INDUSTRIAL


TECHNOLOGY

School Of Computer
Engineering

Dr. Amiya Ranjan Panda


Assistant Professor [II]
School of Computer Engineering,
Kalinga Institute of Industrial Technology (KIIT),
Deemed to be University,Odisha

4 Credit Lecture Note - 01


Chapter Contents
2

ü What is an Operating System ü Memory Management


ü Computer System Structure ü Storage Management
ü Operating System Definition ü Protection and Security
ü What Operating Systems Do ü Command Interpreter System
ü Operating System Evolution ü System Call
ü Types of Operating System ü Wha is Kernel
ü Operating System Servicess ü Operating System Structure
ü Operating System Operations
ü Process Management
What is Operating System
3
q A program that acts as an intermediary between a user of a computer and the
computer hardware.
q Operating system goals:
ü Execute user programs and make solving user problems easier
ü Make the computer system convenient to use
ü Use the computer hardware in an efficient manner
Computer System Structure
4

ü Computer system can be divided into four components:


ü Hardware – provides basic computing resources
§ CPU, memory, I/O devices
ü Operating system
§ Controls and coordinates use of hardware among various
applications and users
ü Application programs – define the ways in which the system
resources are used to solve the computing problems of the users
§ Word processors, compilers, web browsers, database systems,
video games
ü Users
§ People, machines, other computers
Four Components of a Computer System
5

5
What Operating Systems Do
6

ü Depends on the point of view- User, System.


ü Users want convenience, ease of use and good performance
§ Don’t care about resource utilization
ü But shared computer such as mainframe or minicomputer must keep all
users happy.
ü Users of dedicate systems such as workstations have dedicated resources
but frequently use shared resources from servers.
ü Handheld computers are resource poorly optimized for usability and
battery life.
ü Some computers have little or no user interface, such as embedded
computers in devices and automobiles.

6
Operating System Definition
7

q OS is a resource allocator
ü Manages all resources
ü Decides between conflicting requests for efficient and fair resource use
q OS is a control program
ü Controls execution of programs to prevent errors and improper use of
the computer

7
Operating System Evolution
8

q Batch Processing Operating System


q Multiprogramming Operating System
q Timesharing Operating System
q Multitasking Operating System

8
Batch Processing Operating System
9
q Early computers were extremely expensive
ü Important to maximize processor utilization
q Monitor
ü Software that controls the sequence of events
ü Batch jobs together
ü Program returns control to monitor when finished
q The interface to the monitor was accomplished through Job
Control Language (JCL).
q For example, a JCL request could be to run the compiler for a
particular programming language, then to link and load the
program, then to run the user program.
q Hardware features:
ü Memory protection: protect the memory area containing
the monitor from the Utilities
ü Timer: prevents a job from monopolizing the system
q Problems:
ü Bad utilization of CPU time - the processor stays idle
while I/O devices are in use. 9
Multiprogramming Operating System
10
q Multiprogramming is a technique to execute number of programs simultaneously
by a single processor.
q Number of processes reside in main memory at a time.
q The OS picks and begins to execute one of the jobs in the main memory.
q If any I/O wait happened in a process, then CPU switches from that job to another
job.
q Hence CPU in not idle at any time.
q Processor must wait for I/O instruction to complete before preceding.

q When one job needs to wait for I/O, the processor can switch to the other job.

10
Multiprogramming Operating System...
11

OS
Job 1
q Advantages
ü Efficient memory utilization Job 2

ü Throughput increases Job 3


ü CPU is never idle, so performance increases. Job 4
Job 5

11
Time Sharing Systems
12
q Multiprogramming systems : several programs use the computer system
q Time-sharing systems : several (human) users use the computer system
interactively
q Characteristics:
ü Using multiprogramming to handle multiple interactive jobs
ü Processor’s time is shared among multiple users
ü Multiple users simultaneously access the system through terminals
q Time sharing, or multitasking, is a logical extension of multiprogramming
q Multiple jobs are executed by switching the CPU between them
q In this, the CPU time is shared by different processes, so it is called as
“Time sharing Systems”.
q Time slice is defined by the OS, for sharing CPU time between processes.
q Examples: Multics, Unix, etc.,

12
Time Sharing Systems...
13

Multiprogramming Time Sharing

Principal objective Maximize processor use Minimize response time

Source of directives to Job control language Commands entered at the


operating system commands provided with terminal
the job

13
Types of OS
14
q Operating System can also be classified as
ü Single User Systems
ü Multi User Systems
q Single User System: Provides a platform for only one user at a time.
q They are popularly associated with Desk Top operating system which run
on standalone systems where no user accounts are required.
q Example: DOS
q Multi User Systems: Provides regulated access for a number of users by
maintaining a database of known users.
q Refers to computer systems that support two or more simultaneous users.
q Another term for multi-user is time sharing.
q Ex: All mainframes are multi-user systems.
q Example: Unix

14
MS-DOS execution
15

(a) (b)

(a) At system startup (b) running a program

15
Operating System Services
16
q The following are the services provided by the operating system.
ü User Interface
ü Program Execution
ü I/O Operations
ü File-system manipulation
ü Communications
ü Error Detection
ü Resource Allocation
ü Accounting
ü Protection

16
Operating System Services...
17
q User interface - Almost all operating
systems have a user interface (UI)
q A user interface controls how to enter
data and instructions and how
information is displayed on the screen
ü With a graphical user interface
(GUI), user interacts with menus
and visual images
ü With a command-line interface, a
user uses the keyboard to enter
data and instructions
q Program execution - The system
must be able to load a program into
memory and to run that program, end
execution, either normally or
abnormally (indicating error).

17
Operating System Services...
18
q I/O operations - A running program may require I/O, which may involve a file or
an I/O device
One set of operating-system services provides functions that are helpful to the
user:
q File-system manipulation - The file system is of particular interest. Programs need
to read and write files and directories, create and delete them, search them, list file
Information, permission management.
q Communications – Processes may exchange information, on the same computer or
between computers over a network
ü Communications may be via shared memory or through message passing
(packets moved by the OS)
q Error detection – OS needs to be constantly aware of possible errors
ü May occur in the CPU and memory hardware, in I/O devices, in user program
ü For each type of error, OS should take the appropriate action to ensure correct
and consistent computing
ü Debugging facilities can greatly enhance the user’s and programmer’s abilities
to efficiently use the system
18
Operating System Services...
19
Another set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing.
q Resource allocation - When multiple users or multiple jobs running concurrently,
resources must be allocated to each of them
ü Many types of resources - CPU cycles, main memory, file storage, I/O
devices.
q Accounting - To keep track of which users use how much and what kinds of
computer resources
q Protection and security - The owners of information stored in a multiuser or
networked computer system may want to control use of that information,
concurrent processes should not interfere with each other
ü Protection involves ensuring that all access to system resources is controlled
ü Security of the system from outsiders requires user authentication, extends to
defending external I/O devices from invalid access attempts

19
Operating System Services...
20

20
Operating-System Operations
21
q Interrupt driven (hardware and software)
ü Hardware interrupt by one of the devices
ü Software interrupt (exception or trap):
• Software error (e.g., division by zero)
• Request for operating system service
• Other process problems include infinite loop, processes modifying each
other or the operating system

21
Operating-System Operations...
22
q Dual-mode operation allows OS to protect itself and other system components
ü User mode and kernel mode
ü Mode bit provided by hardware
§ Provides ability to distinguish when system is running user code or
kernel code
§ Some instructions designated as privileged, only executable in kernel
mode
§ System call changes mode to kernel, return from call resets it to user
q Increasingly CPUs support multi-mode operations
ü i.e. virtual machine manager (VMM) mode for guest VMs

22
Transition from User to Kernel Mode
23
q Timer to prevent infinite loop / process hogging resources
ü Timer is set to interrupt the computer after some time period
ü Keep a counter that is decremented by the physical clock.
ü Operating system set the counter (privileged instruction)
ü When counter zero generate an interrupt
ü Set up before scheduling process to regain control or terminate program that
exceeds allotted time

23
Process Management
24
q A process is a program in execution. It is a unit of work within the system.
Program is a passive entity, process is an active entity.
q Process needs resources to accomplish its task
ü CPU, memory, I/O, files
ü Initialization data
q Process termination requires reclaim of any reusable resources
q Single-threaded process has one program counter specifying location of next
instruction to execute
ü Process executes instructions sequentially, one at a time, until completion
q Multi-threaded process has one program counter per thread
q The operating system is responsible for the following activities in connection with
process management:
ü Creating and deleting both user and system processes
ü Suspending and resuming processes
ü Providing mechanisms for process synchronization
ü Providing mechanisms for process communication
24
Main Memory Management
25
q To execute a program all (or part) of the instructions must be in memory
q All (or part) of the data that is needed by the program must be in memory.
q Memory management determines what is in memory and when
ü Optimizing CPU utilization and computer response to users
q Memory management activities
ü Keeping track of which parts of memory are currently being used and by
whom
ü Deciding which processes (or parts thereof) and data to move into and out of
memory
ü Allocating and deallocating memory space as needed

25
Storage Management
26
q OS provides uniform, logical view of information storage
ü Abstracts physical properties to logical storage unit - file
ü Each medium is controlled by device (i.e., disk drive, tape drive)
§ Varying properties include access speed, capacity, data-transfer rate,
access method (sequential or random)
q File-System management
ü Files usually organized into directories
ü Access control on most systems to determine who can access what
ü OS activities include
§ Creating and deleting files and directories
§ Primitives to manipulate files and directories
§ Mapping files onto secondary storage
§ Backup files onto stable (non-volatile) storage media

26
I/O Management
27
q One purpose of OS is to hide peculiarities of hardware devices from the user
q I/O subsystem responsible for
ü Memory management of I/O including buffering (storing data temporarily
while it is being transferred), caching (storing parts of data in faster storage
for performance), spooling (the overlapping of output of one job with input
of other jobs)
ü General device-driver interface
ü Drivers for specific hardware devices

27
Secondary Memory Management
28
q 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
q Most modern computer systems use disks as the principal on-line storage medium,
for both programs and data.
q The operating system is responsible for the following activities in connection with
disk management:
ü Free space management
ü Storage allocation
ü Disk scheduling

28
Protection & Security System
29
q Protection – any mechanism for controlling access of processes or users to
resources defined by the OS
q Security – defense of the system against internal and external attacks
ü Huge range, including denial-of-service, worms, viruses, identity theft, theft
of service
q Systems generally first distinguish among users, to determine who can do what
ü User identities (user IDs, security IDs) include name and associated number,
one per user
ü User ID then associated with all files, processes of that user to determine
access control
ü Group identifier (group ID) allows set of users to be defined and controls
managed, then also associated with each process, file
ü Privilege escalation allows user to change to effective ID with more rights

29
Command Interpreter System
30
q 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

30
System Calls
31
q Programming interface to the services provided by the OS
q Typically written in a high-level language (C or C++)
q Mostly accessed by programs via a high-level Application Programming
Interface (API) rather than direct system call use
q Three most common APIs are Win32 API for Windows, POSIX API for POSIX-
based systems (including virtually all versions of UNIX, Linux, and Mac OS X),
and Java API for the Java virtual machine (JVM)

31
What is a kernel?
32
q Operating system provides an hardware abstraction layer
q Since OS provides resource sharing → every access to the hardware from user
programs should be done through the OS
q To enforce this in a secure way, and prevent malicious or buggy applications, a
protection is needed at the hardware level
q Hardware must provide at least two execution levels:
ü Kernel mode: the application has access to all the instructions and every
piece of hardware.
ü User mode: the application is restricted and cannot execute some
instructions, and is denied access to some hardware (like some area of the
main memory
q Two areas are defined at application level:
ü Kernel space: Code running in the kernel mode is said to be inside the
kernel space
ü User space: Every other programs, running in user mode, is said to be in
user space

32
Operating System Structure
33
The OS (a simplified view)

Command Interpreter

Information Services

Error Handling Accounting System


File System

Protection System

Memory Secondary Storage


Process Management Management Management

I/O System

Hardware

33
Operating Systems Structures
34
q Structure/Organization/Layout of OSs
q Monolithic (one unstructured program)
q Layered
q Microkernel
q Virtual Machines
q Monolithic OS:
ü OS is simply a collection of functions
ü One big program including everything (system calls, system programs, every
managers, device drivers, etc)
ü Entire OS resides in main memory
ü Ex: MS-DOS, Multics, Unix, BSD, Linux
ü Most work is done via system calls
ü These are interfaces, that access some subsystem within the kernel such as
disk operations
ü Essentially calls are made within programs and a request is passed through
the system call
34
Monolithic OS...
35
q Pros
ü Every component contained in
kernel
ü direct communication among all
components
ü All OS services operate in kernel
space
ü high performance
q Cons
ü Larger size makes it hard to
maintain
ü Complexity is more
ü Dependencies between system
component
ü not easily extended/modified: new
devices, emerging technologies not
easily added
35
Layered Approach
36
q The operating system is divided into a number of layers (levels), providing
different functionalities
q The bottom layer (layer 0) is the hardware; the highest (layer N) is the user
interface.
q A layer can only use the services provided by layer in a level below
q System calls might pass through many layers before completion
q The operating system is divided into a number of layers (levels), providing
different functionalities
q Pros:
ü Information hiding between layers
ü Increased security and protection
ü Easy to debug, test, and modify OS
q Cons:
ü If one layer stops working, entire system
will stop
ü Mapping overhead between layers
ü Difficult to categorize into layers
36
Microkernel OS
37
q Move as much functionality as possible from the kernel into user space.
q Only a few essential functions in the kernel
ü primitive memory management (address space)
ü I/O and interrupt management
ü Inter-Process Communication (IPC)
ü basic scheduling
q Other OS services are provided by processes running in user mode (vertical
servers):
ü device drivers, file system, virtual memory…
q Communication takes place between user modules using message passing.
q More flexibility, extensibility, portability and reliability.
q But performance overhead caused by replacing service calls with message
exchanges between processes.

37
Microkernel OS
38
q Extensibility/Reliability
ü easier to extend a microkernel
ü easier to port the operating system to new architectures
ü more reliable (less code is running in kernel mode)
ü more secure
ü small microkernel can be rigorously tested.
q Portability
ü changes needed to port the system to a new processor is done in the
microkernel, not in the other services.

38
Virtual Machines
39
q A Virtual Machine (VM) takes the layered and microkernel approach to its logical
conclusion.
q It treats hardware and the operating system kernel as though they were all
hardware.
q A virtual machine provides an interface identical to the underlying bare hardware.
q The operating system host creates the illusion that a process has its own processor
and (virtual memory).
q Each guest provided with a (virtual) copy of underlying computer.
q The resources of the physical computer are shared to create the virtual machines:
ü CPU scheduling can create the appearance that users have their own
processor.
ü Spooling and a file system can provide virtual card readers and virtual line
printers.
ü A normal user time-sharing terminal serves as the virtual machine operator’s
console.

39
40

Anda mungkin juga menyukai