Overview of Operating System
Introduction and Overview
Operating System Structures
FAST-NU Karachi Campus OS Spring 2020 1
Computing Environments
Real-time Embedded Systems
Most prevalent form of computers
Computers found everywhere
• Systems they run on are usually primitive
OS provides limited features
Limited to little or no user interface
• Vary considerably in their capabilities
Embedded systems run real-time operating system
(RTOS)
o Rigid time requirements are imposed on
execution of certain functions
System fails if the time constraints are not met
FAST-NU Karachi Campus OS Spring 2020 2
Operating System Structures
OS Services
Interface for users
Components and their interconnections
FAST-NU Karachi Campus OS Spring 2020 3
Operating System Structures
OS services
Interface of user and OS
OS functions provided through system calls
Types of System calls
Structure of OS
Defining goals of OS
Modularity and Layered approach
Mechanisms and policies
Microkernel and Monolithic OS
FAST-NU Karachi Campus OS Spring 2020 4
Operating System Structures
Viewan OS from several vintage points
Services offered by the OS
Interfaces made available to users and
programmers
Its components and their interconnections
Viewpoints of users, programmers and OS
designers
OS Spring 2020 FAST-NU Karachi Campus 5
Operating-System Services
Identifycommon class of services among all OS
Set of services provided for the convenience of
user
User Interface (UI)
Options are
Command-line Interface (CLI)
Graphical User Interface (GUI)
Touchscreen Interface
Program Execution
The system must be able to load a program
and execute it, terminating normally or
abnormally
I/O operations
OS must provide means to perform I/O
OS Spring 2020 FAST-NU Karachi Campus 6
A View of Operating System Services
OS Spring 2020 FAST-NU Karachi Campus 7
Operating-System Services
File-system manipulation
File management and access control
management features should be provided
Communications
Processes need to communicate with one
another
This can be implemented through message
passing or shared memory
Error detection
Detect errors and take appropriate action
to ensure correct and consistent computing
Set of services for efficient working of system
Resource allocation
Efficient allocation of resources without
error and deadlocks
OS Spring 2020 FAST-NU Karachi Campus 8
Operating-System Services
Accounting
For record-keeping, usage statistics and
future planning
Protection and Security
Processes should not interfere with each
other or with the OS processes
Protection ensures that all accesses to system
resources are controlled
Security ensures that only authorized and
authenticated users access the system and its
resources
Defend all I/O devices from external threats and
invalid attempts
OS Spring 2020 FAST-NU Karachi Campus 9
User Operating-System Interface
There are three approaches for users to
interface with the OS
Command Line Interface (CLI) or
Command Interpreter
Two approaches that use Graphical User
Interface (GUI)
Command Interpreter
Allows users to directly enter commands to
be performed by the OS
A number of interpreters may be available to
choose from
Shells: Bourne shell, Cshell of Unix
How are commands implemented?
There are two ways to implement it
OS Spring 2020 FAST-NU Karachi Campus 10
User Operating-System Interface
Command interpreter itself contains the code to
execute the command
Size is determined from the number of
commands
Commands are implemented through system
programs
Interpreter only identifies which program
to load into memory
• Command Interpreter program is small and it
does not need to change when new commands
are added in the system
Graphical User Interface using touchscreen or
mouse as the pointer
Both CLI or GUI are personal preferences
OS Spring 2020 FAST-NU Karachi Campus 11
System Calls
System calls provide an interface to the services
made available by the OS
How are system calls used?
APIs hide the details of all the operation
sequence
Invokes the functions on behalf of the
application programmer
Provides portability between different
systems
Windows API, POSIX-API, Java API
Systemcall interface (SCI)
Run-time support system for most
programming languages
Serves as the link to the system calls
made available by the OS
OS Spring 2020 FAST-NU Karachi Campus 12
Example of how System Calls are used
Copy
from one
file to
another
OS Spring 2020 FAST-NU Karachi Campus 13
API – System Call – OS Relationship
The handling
of a user
application
invoking the
open() system
call
OS Spring 2020 FAST-NU Karachi Campus 14
System Calls
Why API instead of system call?
Program portability
Handling of system calls in the RTE
Many system calls need parameters to be
passed to the OS – three approaches are used
Pass parameters in registers
Registers are fewer in number
Place the parameters in a block or table in
memory
Place the address of the block in register
Push the parameters onto the stack by the
calling program
Popped off by the OS routine
OS Spring 2020 FAST-NU Karachi Campus 15
Parameter Passing as a Table
OS Spring
FAST-NU 2020 Campus
Karachi 16
Types of System Calls
Systems calls are grouped into six categories
Process control
File management
Device management
Information maintenance
Communications
Protection
Process Control
end, abort load, execute
wait event, signal event
allocate and free memory
create process, terminate process
get process attributes, set process attributes
wait for time
OS Spring 2020 FAST-NU Karachi Campus 17
Examples of Windows and Unix System Calls
OS Spring 2020 FAST-NU Karachi Campus 18
System Calls for Process Control
end, abort
A running process may need to end normally
(end) or abnormally (abort)
Abnormal termination provides the error
code
load, execute
A process may want to load another process
for execution
Where does control return as the new process
terminates?
Depends on whether the existing process is
lost, saved or allowed to continue execution
concurrently
If the return is to the existing process, memory
image of the process should be saved
OS Spring 2020 FAST-NU Karachi Campus 19
System Calls for Process Control
create process, terminate process
New processes may be created by an existing process
set process attributes, get process attributes
This provides the ability to control and set the
attributes of a new process or to determine the
attributes of an existing process
wait for time
Wait for a certain amount of time for a process to
terminate
wait event, signal event
Wait for a specific event or the process itself signals
completion
Other system calls are available for debugging,
getting memory dump, profiling, etc.
OS Spring 2020 FAST-NU Karachi Campus 20
Single-tasking in Arduino
system startup running a program
OS Spring 2020 FAST-NU Karachi Campus 21
FreeBSD Running Multiple Programs
OS Spring 2020 FAST-NU Karachi Campus 22
File Management System Calls
create file, delete file
Requires the name of the file and its attributes
open, close
After creation, file should be opened for
specific operations
read, write, reposition
Operations that can be performed on open file
get file attributes, set file attributes
Get attributes of a file and possibly set them
if desired
Attributes are name, type, protection codes,
accounting information, etc.
Some systems provide more file management
functions and system calls
OS Spring 2020 FAST-NU Karachi Campus 23
Device Management System Calls
Resources controlled by the OS are treated as
devices
Physical and virtual devices
request device, release device
If there are multiple users of various devices,
processes require to request for devices before
making use of it and release it after using it
read, write, reposition
Operations that can be performed on the
devices that are allocated
Get device attributes, set device attributes
Logically attach or detach devices
OS Spring 2020 FAST-NU Karachi Campus 24
Information Maintenance System Calls
System calls that are used only to transfer
information between user and OS programs
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
OS maintains information to respond to the
calls that are relevant
OS Spring 2020 FAST-NU Karachi Campus 25
Communication System Calls
Interprocess communication models
Message-passing model
Processes exchange messages to transfer
information directly or indirectly
Requires the name of the processes
o Shared-memory model
For exchange of information through
common, shared memory areas
create, delete communication connection
A connection is established before messages
are exchanged between processes
send, receive messages
transfer status information
attach or detach remote devices
OS Spring 2020 FAST-NU Karachi Campus 26
Protection Related System Calls
Protectionprovides a mechanism for controlling
access to resources provided by a computer
system
Set_permission and get_permission
Manipulates permission settings of resources
such as files and disks
Allow_user and deny_user
Whether users be allowed or not allowed
access to certain resources
OS Spring 2020 FAST-NU Karachi Campus 27
System Services
Provide a convenient environment for program
development and execution – system utilities
Varies from simple to complex ones
Divided into a number of categories
File management
Programs that manipulate files and directories
Status information
Programs that format and print the output
from the status information system calls
Registry may be supported that store
and retrieve configuration information
File modification
Several text editors may be available with
various options like search or
transformations
OS Spring 2020 FAST-NU Karachi Campus 28
A View of Operating System Services
OS Spring 2020 FAST-NU Karachi Campus 29
System Services
Programming language support
Compilers, assemblers, debuggers and
interpreters for common programming
languages
Program loading and execution
Used for loading and execution of programs
Communications
Provide mechanism for creating virtual
connections among processes, users and
computer systems
Other programs are supplied: perform common
operations: web browsers, spreadsheets, etc.
OS Spring 2020 FAST-NU Karachi Campus 30
Why are applications OS Specific?
Each OS provides a unique set of system
calls
An application can be made to run on multiple
OS through one of three ways:
1. Application can be written in an interpreted
language that has an interpreter available for
multiple OS
Python or Ruby
Features are limited
Performance suffers
2. Application is written in a language that
includes virtual machine running the
application
Java and JVM
OS Spring 2020 FAST-NU Karachi Campus 31
Why are applications OS Specific?
o Suffers from similar disadvantages as in the
first approach
3. Application developer can use a standard
language or API which generates binaries in a
machine- and OS-specific language
POSIX API and its set of standards
Developing cross platform application is a
challenging task
Other challenges exist at the lower levels of
the system
OS Spring 2020 FAST-NU Karachi Campus 32
Operating-System Design and Implementation
Design Goals
Define goals and specifications
Affected by the choice of hardware and the
type of system
General purpose or specific
Next level requirements: user and system
goals
User goals
System should be convenient to use
It should be reliable, safe and fast
How to achieve these objectives?
System goals
System should be easy to design, implement
and maintain - It should be flexible, reliable,
error free and efficient
OS Spring 2020 FAST-NU Karachi Campus 33
Mechanisms and Policies
An important principle of OS design is to
separate policy from mechanism
Mechanisms determine how to do something
Policies determine what will be done
This is important for flexibility
Policies are likely to change over time and
place
A general mechanism insensitive to policy
changes is desirable
Microkernel-based OS separate mechanisms
from policies
Implements basic set of primitive building
blocks that are totally policy free
OS Spring 2020 FAST-NU Karachi Campus 34
Implementation
Allcurrent generation OS is implemented in a
high-level language
Easier to write, understand and debug
Portability is achieved
May suffer from reduced speed and increased
storage requirements
Performance improvement measures can be
used to offset the disadvantage
Bottleneck routines can be identified and
replaced with assembly language equivalents
Bottleneck is identified through programs
that measure system behavior
Traces can be run to achieve the objectives
OS Spring 2020 FAST-NU Karachi Campus 35
Operating System Structure
Designthe system by defining small
components or modules
Each module is a well-defined portion of
the system with carefully defined interfaces
and functions
Monolithic Structure
Simplest structure has no structure
Monolithic structure
Original UNIX operating system had limited
structuring
Consists of two separable parts
The kernel and system programs
OS Spring 2020 FAST-NU Karachi Campus 36
Traditional UNIX System Structure
OS Spring 2020 FAST-NU Karachi Campus 37
Linux
System
Struct-
ure
OS Spring 2020 FAST-NU Karachi Campus 38
Layered Approach
Monolithic approach is a tightly coupled system
A loosely coupled system is divided into
separate smaller components
Changes in one component affects only that
component
Modular system can be designed using a number
of approaches
Layered approach
OS is broken into a number of layers or levels
Bottom layer is the hardware and the
highest layer is the user interface
An OS layer is an implementation of an
abstract object made up of data and the
operations that can manipulate those data
OS Spring 2020 FAST-NU Karachi Campus 39
Layered Operating System
OS Spring 2020 FAST-NU Karachi Campus 40
Layered Approach
Advantages of layered approach
Simplicity of construction and debugging
Simplifies system verification
Problems with layered approach
How to appropriately define the layers
Some layers may not be completely self-
contained violating the basic principle of
layered approach
Less efficient in terms of performance
Recentdevelopments
Fewer layers with more functionality have
been designed to overcome the above
problems
OS Spring 2020 FAST-NU Karachi Campus 41
Microkernels
This method structures the kernel by removing
all nonessential components and implements
them as system and user-level programs
Results in smaller kernel
Microkernel provides minimal process and
memory management and some communication
facility
Communication is through message passing
Benefits of microkernel approach
Ease of extending the OS
Easier to port
It provides more security and reliability
Examples are Tru64 UNIX and QNX
This approach suffers from performance losses
OS Spring 2020 FAST-NU Karachi Campus 42
Architecture of a Typical Microkernel
OS Spring 2020 FAST-NU Karachi Campus 43
Modules
Current methodology is to use loadable kernel
modules (LKMs)
Kernel has a set of core components
Links dynamically with additional services
during boot time or during run time
o Linux uses LKMs for dev. drivers and file system
Current implementations of UNIX uses this
methodology
Solaris, Mac OS X, Windows, etc.
Hybrid Systems
Most of the operating systems are a hybrid of
the previously mentioned structures
They address the issues of performance,
security and usability
OS Spring 2020 FAST-NU Karachi Campus 44
Hybrid Systems
Linux and Windows are primarily monolithic
New functionalities can be added to Linux
kernel dynamically
o Windows also support LKMs and has some
behavior of microkernel systems
Operating Systems for mobile devices
iOS
Android
Reading Assignment
OS Spring 2020 FAST-NU Karachi Campus 45
Part 2
Process Management
Processes
Threads
Process Synchronization
CPU Scheduling
Deadlocks
OS Spring 2020 FAST-NU Karachi Campus 46
Process Management
A process is a program in execution
Needs resources to accomplish its task
System consists of a collection of processes
executing concurrently
OS processes and user processes
Processes may be of single thread or may have
multiple threads
The threads may run in parallel on systems with
multiple hardware processing cores
Scheduling of threads on cores
Several CPU schedulers are available to
programmers
OS Spring 2020 FAST-NU Karachi Campus 47
Process Concept
Definitions
States of a process
Process Control Block
Threads of a process
Scheduling and schedulers
Scheduling queues
Operations on processes
Process creation and termination
Communication between processes
IPC using shared memory and message
passing
OS Spring 2020 FAST-NU Karachi Campus 48
Process Concept
All activities including OS programs and user
programs are termed as processes
Job and process are terms used
interchangeably
A process comprises of
A program code or text section
Program counter content and content of
processor registers
Process stack and a data section
It may also contain a heap that is
dynamically allocated at run time
Two processes may be associated with the
same program but are considered to be
separate processes
OS Spring 2020 FAST-NU Karachi Campus 49
Process in Memory
OS Spring 2020 FAST-NU Karachi Campus 50
Process State
Processes change states as they execute
New: The process is being created
Running: Instructions are being executed
Only one process can be running on a single
core processor in system at any instant
Waiting: The process is waiting for some
event to occur
Ready: The process is waiting to be
assigned to the processor
Many processes may be ready and waiting
Terminated: The process has completed
execution
OS Spring 2020 FAST-NU Karachi Campus 51
Diagram of Process State
OS Spring 2020 FAST-NU Karachi Campus 52
Process Control Block
Each process in the system is represented by a
task control or a process control block (PCB)
PCB serves as the repository for information
that may vary from process to process
Includes the following information
Process state
Program counter
CPU registers
Number and type depends on the
processor architecture
CPU scheduling information
Contains scheduling parameters
Memory management information
Accounting information
I/O status information
OS Spring 2020 FAST-NU Karachi Campus 53
Process Control Block (PCB)
OS Spring 2020 FAST-NU Karachi Campus 54