DAYANANDA SAGAR COLLEGE OF ENGINEERING
DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING
UNIT 1/MODULE 1
Chapter 1: Introduction to Operating System
Contents:
What Operating Systems Do
Operating-System Structure
Operating-System Operations
1.1 What Operating Systems Do
Operating system is software that controls and manages the computer hardware.
Operating system acts as an interface between user and hardware of a computer
system.
Operating system provides an environment for execution of a program in convenient
and efficient way.
A program that acts as an intermediary between a user of a computer and the
computer hardware.
What Operating Systems Do: Goals
User Computations
Execute user programs and make solving user problems easier
Utilization Efficiency
To ensure good resource utilization efficiency and provide appropriate
corrective actions when it becomes low
User Convenience
Make the computer system convenient to use
Four Components of a Computer System
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
----------------------------------------------------------------------------------------------------------------
---------------------
1.1.1 Operating System: Different Views
User view
Personal Computer: Ease of use, performance
Mainframe: Resource utilization
System view
Resource allocator
Control program
System View
OS is a resource allocator
Manages all resources
Decides between conflicting requests for efficient and fair resource use
OS is a control program
Controls execution of programs to prevent errors and improper use of the
computer
Defining Operating System
“The one program running at all times on the computer” is the kernel.
Everything else is either a system program (ships with the operating system) or an
application program
Computer System Organization
Computer-system operation
Storage Structure
I/O Structure
1.2 Operating System Structure: Multiprogramming
Needed for efficiency
Single user cannot keep CPU and I/O devices busy at all times
Multiprogramming organizes jobs (code and data) so CPU always has one to execute
A subset of total jobs in system is kept in memory
One job is selected and run via job scheduling
When it has to wait (for I/O for example), OS switches to another job and so on
I/O routine is supplied by system to many programs.
CPU scheduling: the system must choose one job among several jobs ready to run.
Allocation of devices should be done efficiently and fairly.
1.2.2 Operating System Structure:
Timesharing (multitasking)
Time-Sharing is a logical extension of Multiprogramming where many users share the
system simultaneously.
The CPU executes several jobs that are kept in memory by switching among them.
CPU switching is so fast that the user can interact with each program while it is
running.
Response time is < 1 second
Few processes should be available
Several jobs are ready to be brought in memory à job scheduling
Several jobs ready to run at the same time à CPU scheduling
If processes don’t fit in memory, swapping moves them in and out from the memory
à memory management
Virtual memory allows execution of processes not completely in memory
1.3 Operating-System Operations
OS is interrupt driven
A trap or exception is a software generated interrupt
Division by zero or invalid memory access
Other process problems include infinite loop, processes modifying each other
or the operating system
Request for operating system service
For each type of interrupt, a service routine is responsible in OS
1.3.1 Dual mode Operation
As OS and users share hardware and software, they should not interfere in each other
operations.
Dual-mode operation allows OS to protect itself and other system components
User mode
Kernel mode or system mode or privileged mode
A bit, mode bit, is added to computer hardware to indicate the current mode
Kernel (0)
User (1)
When a user process requests a service from OS via a system call, it transit from user
mode to kernel mode to fulfill the request
At boot time, hardware starts in kernel mode, then OS is loaded (mode bit = 0)
Then OS starts user applications in user mode (mode bit = 1)
Whenever a trap or interrupt occurs, hardware switches from user to kernel mode
(mode bit = 0)
When a user process requests a service from OS via a system call, it transit from user
mode to kernel mode to fulfill the request
Mode bit provided by hardware
Provides the means for protecting the OS from erroneous programs and
erroneous programs from each other.
Provides ability to distinguish when system is running user mode or kernel
mode
Some instructions designated as privileged, only executable in kernel mode
If any attempt is made to execute privileged instructions in user mode, hardware does
not execute these instructions and treats as traps
MS-DOS written for Intel 8088 architecture which has no mode bit and
therefore no dual mode.
A user program may wipe the OS by writing over it.
Pentium provides dual mode; and Windows, Linux, Solaris make use of the feature
and provide protection to OS
Transition from User to Kernel Mode
1.3.2 Timer
A user program should not stuck in infinite loop i.e. not returning to OS.
Timer can be used to prevent infinite loop or process hogging resources
A timer can be set to interrupt the computer after a specified period.
The period may be fixed (1/60 sec) or variable (from 1 milisecond to 1 second)
A variable timer is implemented by a clock and a counter
At each click OS decrements counter
At 0, an interrupt occurs
Set up timer before scheduling process to regain control or terminate program that
exceeds allotted time
UNIT 1/MODULE 1
Chapter 2: System Structure
Contents:
Operating System Services
System Calls
Types of System Calls
2.1 Operating System Services
An operating system provides the environment within which programs are executed.
Services provided by OS
Interface to users and programmers
Its components and their interconnection
User Interface
Program execution
I/O operations
File-system manipulation
Communications
Error detection
Resource allocation
Accounting
Protection and Security
a. User Interface
Almost all operating systems have a user interface (UI)
Command-Line Interface (CLI) uses text command
Batch Interface uses files for execution containing commands and directives
Graphics User Interface (GUI) is window and uses pointing device, keyboard, menus
etc.
Some systems use two or all three types.
b. Program execution
(system capability to load a program into memory and to run it)
Load the instructions and data into main memory
Initialize I/O devices and required files
Make resources available for execution
End execution, either normally or abnormally (indicating error)
c. I/O operations
a. A running program may require I/O which may involve a file to load in memory
or an I/O device like keyboard
b. Since user programs cannot execute I/O operations directly due to efficiency and
protection purpose, the operating system must provide means to perform I/O.
c. A uniform interface to hide the hardware details
d. File-system manipulation
a. Programs need to read and write files and directories,
b. Create and delete files and directories
c. Search them, list file Information
d. Permission management to allow or deny access to files and directories based on
ownership and privileges
e. Communications
a. Exchange of information between processes executing either on the same
computer or on different systems tied together by a network.
b. Implemented via shared memory or message passing.
f. Error detection
a. OS needs to be constantly aware of possible errors
b. OS ensures correct and consistent computing by detecting errors in the CPU,
memory hardware, I/O devices, or in user programs.
i. Illegal memory location
ii. Printer not ready and other I/O devices related
iii. Power failure and Connection failure in network
iv. Software errors like arithmetic errors, divided by zero
c. Debugging facilities can greatly enhance the user’s and programmer’s abilities to
efficiently use the system
Operating System Services (Additional)
a. Resource allocation
Allocating resources to multiple users or multiple jobs running at the same time
CPU cycle (CPU scheduling)
Memory (Memory management)
File storage (Disk scheduling)
I/O devices (request and release)
Registers (Job scheduling)
b. Accounting
To keep track of which users use how much and what kinds of computer resources
This record keeping may be used for account billing or for accumulating usage
statistics.
Usage statistics is a valuable tool for researcher to reconfigure the system to improve
computing services
c. Protection and Security–ensuring that access to system resources is controlled
The owners of information stored in a multiuser or networked computer system may
want control use of that information
Concurrent processes should not interfere with each other or with OS itself
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
If a system is to be protected and secure, precautions must be instituted throughout it.
Important issues related to Protection and Security are:
Authentication
Controlled access of files
Authorization & privileges
========================================================================
===
2.2 SYSTEM CALLS
System calls provide an interface to the services provided by the OS
These routines are written in a high-level language (C or C++), low level tasks may be in
assembly language
System call sequence to copy the contents of one file to another file
System calls are mostly accessed by programs via a high-level Application Program
Interface (API) rather than directly using system call.
The API specifies a set of functions that are available to an application programmer, including
the parameters that are passed with each function.
Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based
systems (including all versions of UNIX, Linux, and Mac OS X), and Java API for the Java
virtual machine (JVM)
One benefit of using API is program portability.
A program having APIs can be compiled and run on any system that support the same API.
Actual system calls can be more detailed and it is difficult to work with them.
A run-time support system for most of the programming languages provides a system call
interface that serves as the link to system calls made available by OS.
A run-time support system provides a set of functions built into libraries included with the
compiler
A number is associated with each system call.
System-call interface maintains a table indexed according to these numbers.
The system call interface invokes intended system call in OS kernel and returns status of the
system call with its return value.
The programmers need not know about the system call implementation and just need to obey
API
Most of the details of OS interface are hidden from programmer by API and managed by run-
time support library (set of functions built into libraries included with compiler)
More information like parameters is required than simply identity of desired system call
Three general methods are used to pass parameters between a running program and the
operating system.
Pass parameters in registers (simplest)
Store the parameters in a block of memory, and the memory address is passed as a
parameter in a register as in Linux, Solaris
Push the parameters onto the stack by the program, and pop off the stack by operating
system.
2.3 TYPES OF SYSTEM CALLS
Process control
File management
Device management
Information maintenance
Communications
2.3.1 Process control
To halt the execution of a running program either normally (end) or abnormally (abort), OS
transfers the to command interpreter
A process executing one program may load or execute another program
For coordination of concurrent processes, system calls may be wait event, signal event
Another set of system calls help in debugging the program
end, abort
load, execute
create process, terminate process
get process attributes, set process attributes
wait for time
wait event, signal event
allocate and deallocate memory
MS DOS environment
FreeBSD Running Multiple Programs
2.3.2 File management
Create and delete a file (or directory), need a file name and few attributes
Open to read, write and reposition file
Close the file
Determine the values of various file attributes like file name, file type, protection codes
Calls to move and copy files
Some OS may provide API and system programs
create file, delete file
open, close
read, write, reposition
get file attributes, set file attributes
2.3.4 Device management
A process needs several resources for execution like main memory, disk drives, files etc.
All resources may be considered as devices which can be requested and released. (same as
open and close a file)
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
2.3.5 Information maintenance
Many system calls exist for the purpose of transferring the information between the user
program and OS
System calls to return time and date
System calls to return information about the system such as number of current users, OS
version, amount of free memory or disk
System calls to return to get and set the information for files, processes, devices
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
2.3.6 Communications
Types of interprocess communication:
Message passing
Shared memory
Message can be exchanged directly or indirectly
Connection to be established
communicators (processes) should be specified which may be identified by process-
ids on same or different computers identified by IP address
Message transfer through read and write calls
Communication can take place through shared memory
Shared memory to be created
Gaining access to regions of shared memory owned by other processes
Processes can exchange the information by reading and writing the data in shared
memory
Threads share the memory by default
Message passing is useful for exchanging smaller amount of data
Shared memory is faster and can be done in same computer but synchronization is the issue
create, delete communication connection
send, receive messages
transfer status information
attach or detach remote devices