Unit-1_315b458c6da4f4ad3b52934054c48ff1
Unit-1_315b458c6da4f4ad3b52934054c48ff1
HYDERABAD-75
Department of Computer Science and Engineering
BE ¾ (CSE-1) V-Semester
Operating System Roles:
Abstraction - Allow applications to reuse common facilities; make different devices
look the same; provide higher level or more useful functionality
Resource Management: protect applications at a common layer; provide efficient
access to resources (cost, time, energy); provide fair access to resources
Operating System:
A program that acts as an intermediary between a user of a computer and the computer
hardware
Performs all the basic tasks like file management, memory management, process
management, handling I/O, and controlling peripheral devices such as disk drives and
printers
Some popular OS: GNU/Linux (Ubuntu, Fedora, CentOS, Debian, Kali, etc.),
Windows, Android, macOS, Chrome OS, FreeBSD.
What an OS does?
Different perspectives
Desktop computers – convenience, ease of use, good performance, don’t care about
resource utilization
Shared computers such as mainframe or microcomputers – make the users happy,
efficiency.
Workstations – dedicated resources but frequently use shared resources from servers.
Mobile devices like laptops, smart phones, tabs- poor resource utilization, optimized
for usability and battery life; touch screens, voice recognition.
Embedded computers: have little or no user interface; run primarily without user
intervention.
Computer Start-up:
Bootstrap program is loaded at power-up or reboot
• Typically stored in ROM or EPROM, generally known as firmware
• Initializes all aspects of system
• Loads operating system kernel and starts execution
Types of Operating Systems: There are several types’ operating systems depending on
computing environment. Some of them are
Batch operating systems
Multi-programming operating systems
Multi-processing systems
Multi-tasking operating systems
Time-sharing operating systems
Distributed operating systems
Network operating systems
Embedded or Real-time operating systems
Mobile operating systems
Cloud-based operating systems
Batch Operating System: This type of operating system, user does not interact with the
computer directly. There is an operator which takes similar jobs having the same requirement
and groups them into batches. It is the responsibility of the operator to sort with similar needs.
Advantages:
Multi Programming increases the Throughput of the System.
It helps in reducing the response time.
Multi-Processing Operating Systems: is a type of operating system, in which more than one
CPU is used for the execution of processes. It provides better throughput of the system.
Figure 5: Multi-Processing
Advantages:
It increases the throughput of the system.
Even one processors one processor fails, we can proceed with another processor.
Disadvantages:
Due to the multiple CPU, it can be more complex and somehow difficult to understand.
Advantages
Multiple Programs can be executed simultaneously.
It comes with proper memory management.
Disadvantages
The system gets heated in case of heavy programs multiple times
Time-Sharing Operating System: This type of operating systems allows multiple tasks to run
simultaneously where each task is given some time to execute smoothly. Each user gets the
time of the CPU as they use a single system. These systems also known as Multitasking
Systems. The task can be from a single user or different users also. The time that each task gets
to execute is called “quantum”. After this time interval is over, OS switches to the next task.
Advantages of Time-Sharing OS
Each task gets an equal opportunity.
Fewer chances of duplication of software.
CPU idle time can be reduced.
Resource Sharing: Time-sharing systems allow multiple users to share hardware
resources such as the CPU, memory, and peripherals, reducing the cost of hardware and
increasing efficiency.
Improved Productivity: Time-sharing allows users to work concurrently, thereby
reducing the waiting time for their turn to use the computer. This increased productivity
translates to more work getting done in less time.
Improved User Experience: Time-sharing provides an interactive environment that
allows users to communicate with the computer in real time, providing a better user
experience than batch processing.
Disadvantages of Time-Sharing OS
Reliability problem.
One must have to take care of the security and integrity of user programs and data.
Data communication problem.
High Overhead: Time-sharing systems have a higher overhead than other operating
systems due to the need for scheduling, context switching, and other overheads that
come with supporting multiple users.
Complexity: Time-sharing systems are complex and require advanced software to
manage multiple users simultaneously. This complexity increases the chance of bugs
and errors.
Security Risks: With multiple users sharing resources, the risk of security breaches
increases. Time-sharing systems require careful management of user access,
authentication, and authorization to ensure the security of data and software.
Distributed Operating Systems: These types of operating systems are recent advancement in
the world of computer technology and being widely used. Various autonomous interconnected
computers communicate with each other using a shared communication network. Independent
system possess their own memory unit and CPU. These are referred to as loosely coupled
systems or distributed systems. These systems’ processors differ in size and function. The
major benefit of working with these types of the operating system is that it is always possible
that one user can access the files or software which are not actually present on his system, but
some other system connected within this network (i.e. remote access is enabled within the
devices connected in that network).
Figure 8: Distributed OS
Network Operating System (NOS): These systems run on a server and provide the capability
to manage data, users, groups, security, applications, and other networking functions. These
types of operating systems allow shared access to files, printers, security, applications, and
other networking functions over a small private network. One more important aspect of NOS
is that all the users are well aware of the underlying configuration, of all other users within the
network, their individual connections, etc. and why these computers are popularly known as
tightly coupled systems.
Figure 9: Network Operating System
Examples of Network Operating Systems are Microsoft Windows Server 2003, Microsoft
Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, BSD, etc.
Real-Time Operating Systems: These types of operating systems serve real-time systems.
The time interval required to process and respond to inputs is very small. This time interval is
called response time.
Real-time systems are used when there are time requirements that are very strict like missile
systems, air traffic control systems, robots, etc.
Advantages of RTOS
Maximum Consumption: Maximum utilization of devices and systems, thus more
output from all the resources.
Task Shifting: The time assigned for shifting tasks in these systems is very less. For
example, in older systems, it takes about 10 microseconds in shifting from one task to
another, and in the latest systems, it takes 3 microseconds.
Focus on Application: Focus on running applications and less importance on
applications that are in the queue.
Real-time operating system in the embedded system: Since the size of programs is
small, RTOS can also be used in embedded systems like in transport and others.
Error Free: These types of systems are error-free.
Memory Allocation: Memory allocation is best managed in these types of systems.
Disadvantages of RTOS
Limited Tasks: Very few tasks run at the same time and their concentration is very
less on a few applications to avoid errors.
Use heavy system resources: Sometimes the system resources are not so good and
they are expensive as well.
Complex Algorithms: The algorithms are very complex and difficult for the designer
to write on.
Device driver and interrupt signals: It needs specific device drivers and interrupts
signal to respond earliest to interrupts.
Thread Priority: It is not good to set thread priority as these systems are very less
prone to switching tasks.
Memory Management:
To execute a program all (or part) of the instructions must be in memory
All (or part) of the data that is needed by the program must be in memory
Memory management determines what is in memory and when
• Optimizing CPU utilization and computer response to users
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
File Management:
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)
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
Cache Management:
Important principle, performed at many levels in a computer (in hardware, operating
system, software)
Information in use copied from slower to faster storage temporarily
Faster storage (cache) checked first to determine if information is there
• If it is, information used directly from the cache (fast)
• If not, data copied to cache and used there
Cache smaller than storage being cached
• Cache management important design problem
• Cache size and replacement policy
Figure 11: Characteristics of various types of memor
I/O Subsystem:
One purpose of OS is to hide peculiarities of hardware devices from the user
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
Protection and Security:
Protection – any mechanism for controlling access of processes or users to
resources defined by the OS
Security – defense of the system against internal and external attacks
• Huge range, including denial-of-service, worms, viruses, identity theft, theft
of service
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
Virtualization:
Allows operating systems to run applications within other OSes
• Vast and growing industry
Emulation used when source CPU type different from target type (i.e. PowerPC to
Intel x86)
• Generally slowest method
• When computer language not compiled to native code – Interpretation
Virtualization – OS natively compiled for CPU, running guest OSes also natively
compiled
• Consider VMware running WinXP guests, each running applications, all on
native WinXP host OS
• VMM (virtual machine Manager) provides virtualization services
Use cases involve laptops and desktops running multiple OSes for exploration or
compatibility
• Apple laptop running Mac OS X host, Windows as a guest
• Developing apps for multiple OSes without having multiple systems
• Quality assurance testing applications without having multiple systems
• Executing and managing compute environments within data centers
VMM can run natively, in which case they are also the host
• There is no general-purpose host then (VMware ESX and Citrix XenServer)
Touchscreen Interface:
Touchscreen devices require new interfaces
• Mouse not possible or not desired
• Actions and selection based on gestures
• Virtual keyboard for text entry
Voice commands
System Calls: Provide an interface to the services made available by an operating system.
These calla are generally available as functions written in C and C++, although certain low-
level tasks (ex: where hardware must be accessed directly) may have to be written using
assembly-language instructions. Ex: cp, mv, ls, mkdir, ps etc.
Genrally, operating system execute thousands of system calls per second. Most
programmers never see this level of detail, however the application developers design programs
according to an Application Programming Interface (API). Three most common APIs are:
Microsoft API for Windows systems
POSIX API for POSIX-based system (Unix, Linux, and MacOS), and
Java API for programs that run on the Java Virtual Machine
A programmer accesses an API via a library code provided by the OS. In case of UNIX and
Linux, for programs written in C language, the library is called libc.
An example system call:
Run-time environment (RTE): It is an important factor in handling system calls. It is the full
suite of software needed to execute applications written in a given programming language,
including its compilers, or interpreters as well as other software, such as libraries and loaders.
The RTE provides a system call interface that serves as the link to the system calls made
available by the operating system.
The system call interface intercepts function calls in the API and invokes the necessary
system calls within the OS. Each system call is associated with a number, and the system call
interface maintains a table indexed according to these numbers. The system call interface then
invokes the intended system call in the OS kernel and returns the status of the system call.
The caller need know nothing about how the system call is implemented or what it does
during execution. Rather, the caller need only obey the API and understand what the OS will
do as a result of the execution of that system calls. Thus the details of the OS interface are
hidden from the programmer by the API and are managed by the RTE. The Fig 14 illustrates
how the OS handles a user application invoking the open() system call.
Figure 14: Handling of user application invoking the open() system call
System calls occur in different ways depending on the computer in use. Three general methods
are used to pass parameters to the OS.
Pass the parameters in registers – (simplest approach),
Store the parameters in a block, or table in memory and the address of the block is
passed (this approach useful when the parameters are more than registers), and
Parameters are placed or pushed onto a stack (do not limit the number of parameters).
Types of System calls: System calls are grouped roughly into six major categories:
1. Process control
2. File control
3. Device management
4. Information management
5. Communication, and
6. Protection.
System Programs:
Provide a convenient environment for program development and execution. They can
be divided into:
• File management
• Status information sometimes stored in a file
• Programming language support
• Program loading and execution
• Communications – pipe,
• Background services – fg, bg etc.
• Application programs – bc, vi etc.
Most users’ view of the operating system is defined by system programs, not
the actual system calls
File management: Create, delete, copy, rename, print, dump, list, and generally
manipulate files and directories
Status information: used to get the system information like date, time, amount
of available memory, disk space, number of users, detailed performance,
logging, and debugging information, registry to store and retrieve configuration
information
File modification: The programs like text editors to create and modify files,
special commands to search contents of files or perform transformations of the
text
Programming-language support - Compilers, assemblers, debuggers and
interpreters sometimes provided
Program loading and execution- Absolute loaders, relocatable loaders,
linkage editors, and overlay-loaders, debugging systems for higher-level and
machine language
Communications - Provide the mechanism for creating virtual connections
among processes, users, and computer systems. Allow users to send messages
to one another’s screens, browse web pages, send electronic-mail messages, log
in remotely, transfer files from one machine to another
Implementation:
Much variation
• Early OSes in assembly language
• Then system programming languages like Algol, PL/1
• Now C, C++
Actually usually a mix of languages
• Lowest levels in assembly
• Main body in C
• Systems programs in C, C++, scripting languages like PERL, Python, shell
scripts
More high-level language easier to port to other hardware
• But slower
Emulation can allow an OS to run on non-native hardware
Layered Approach:
OS is divided into a number of layers
(levels), each built on top of lower layers.
Bottom layer (0), is the hardware; the
highest (N) is the user interface.
With modularity, layers are selected such
that each uses functions (operations) and
services of only lower-level layers
Adv:
Simplicity of construction and
debugging
Figure 18: Example for layered structure
Hybrid (Monolithic plus Modular)
Microkernel Structure
Moves as much from the kernel into user space
Mach is an example of microkernel
• Mac OS X kernel (Darwin) partly based on Mach
Communication takes place between user modules using message passing
Benefits:
• 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
Detriments:
• Performance overhead of user space to kernel space communication
Hybrid Systems:
Most modern operating systems are not one pure model
• Hybrid combines multiple approaches to address performance, security,
usability needs
• Linux and Solaris kernels in kernel address space, so monolithic, plus modular
for dynamic loading of functionality
• Windows mostly monolithic, plus microkernel for different subsystem
personalities
Apple Mac and iOS: Apple’s macOS is designed to run primarily on desktop and
laptop computer systems, iOS is a mobile OS designed for the iPhone smartphone and
iPad tablet computer. Follows layered architecture and various layers are:
• User experience layer: defines the software interface that allows users to
interact with the computing devices. macOS uses Aqua UI, which is designed
for a mouse or trackpad, whereas iOS uses the Springboard UI, which is
designed for touch devices
• Application framework layer: includes
the Cocoa and Cocoa Touch frameworks,
which provide an API for the Objective-
C and Switft programming languages.
The primary difference between Cocoa
and Cocoa Touch is that former is used
for developing macOS application and
the latter is by iOS to provide support for
hardware features unique to mobile
devices, such as touch screens
• Core framework: This layer defines
frameworks that supports graphics and
media including Quicktime and OpenGL. Figure 21: Structure of Darwin
• Kernel Environment: also know ad
Darwin, includes the Mach microkernel and BSD UNIX kernel.
System Boot: It is the process of starting a computer by loading the kernel. Also called
booting. On most systems, the boot process proceeds as follows:
1. A small piece of code known as the ‘bootstrap program’ or ‘boot loader’ locates the
kernel.
2. The kernel is loaded memory into and started.
3. The kernel initializes hardware.
4. The root file system is mounted.
Multistage Boot Process: When the computer is first powered on, a small boot loader located
in the non-volatile firmware known as BIOS is run. This loads the boot block where it contains
the entire operating system and the OS runs. Many recent computer systems have replaced the
BIOS-based boot process with UEFI or GRUB. In addition to loading the OS, the BIOS or
other loader performs variety of tasks such as diagnostics to determine the state of the machine-
inspecting memory, CPU and discover devices. If the diagnostic process passes, the program
continue with the booting steps of initialization of registers, mounting of file systems.
Unified Extensible Firmware Interface (UEFI): has several advantages over BIOS,
including better support for 64-bit systems, and larger disks. Since UEFI is a single, complete
boot manager and therefore is faster than multistage BIOS boot process.
GRUB: is an open-source bootstrap program for Linux and UNIX systems. Boot parameters
for the system are set in a GRUB configuration file, which is loaded at start-up. GRUB is
flexible and allows changes to be made at boot time, including modifying kernel parameters
and even selecting among different kernels that can be booted. Example to change kernel
parameters, change in the file /proc/cmdline, which is used at boot time:
BOOT_IMAGE is the name of the kernel image to be loaded into memory, and root specifies
a unique identifier of the root file system.
To save space as well as decrease boot time, the Linux kernel image is a compressed
file that is extracted after loaded into the memory. During boot process, the boot loader
typically creates a temporary RAM file system, known as ‘initrams’. This file system contains
device drivers and kernel modules that must be installed to support the real root file system
(which is not in main memory). Once the kernel started and the necessary drivers are installed,
the kernel switches the root file system from the temporary RAM location to the appropriate
toot file system location. Finally, Linux creates the ‘systemd’ process, the initial process in the
system, and then starts other services.
Boot process is slightly different for mobile systems from that for traditional PCs. Ex:
Android does not use GRUB and instead leaves it up to vendors to provide boot loaders. The
most common Android boot loader is LK (for “little Kernel”). Android systems use the same
compressed kernel image as Linux, as well as an initial RAM file system. However, it discards
the ‘initramfs’ once all necessary drivers have been loaded, Android maintains ‘initramfs’ as
the root file system for the device. Once the kernel has been loaded and the root file system
mounted, Android starts the init process and creates a number of services before displaying the
home screen.
Boot loader for most operating systems- including Wwindows, Linux, and macOS, as
well as both iOS and Android – provide booting into recovery mode or a single-user mode for
diagnosing hardware issues, fixing corrupt file systems, and even reinstalling the OS. In
addition to hardware failures, computer systems can suffer from software errors and poor OS
performance – OS provides debugging and performance tuning tools
Failure Analysis: error information is stored in log files. OS can also take a core dump – a
capture of memory of the file. Also crash dump will be provided to debug kernel level crash.
Performance Monitoring and Tuning: several tools that can be used either process-level or
system-wide. Some of the approaches are: counters or tracing.
Counters: OS keep track of system actively through a series of counters such as the number
of system calls made or the number of operations performed to a network device or disk. Some
of the Linux commands are:
Per-process:
ps: reports information for a single process or selection of process
top/htop: reports real-time statistics for current processes.
System-wide:
vmstat: reports memory-usage statistics.
netstat: reports statistics for network interfaces
iostat: reports I/O usage for disks
Tracing: counter-based tools simply inquire on the count value of certain statistics that are
maintained by the kernel, whereas tracing tools collect data for a specific event. Such as steps
involved in a system call invocation. Some Linux examples are:
Per-Process:
strace- traces system calls invoked by a process
gdb- a source-level debugger
System-wide
perf- a collection of Linux performance tools
tcpdump – collects network packets
BCC (BPF Compiler Collection): Debugging tool that provides a dynamic, secure, low-
impact debugging environment to check the interactions between the user-level and kernel
code. It is a front-end interface to the eBPF (extended Berkeley Packet Filter) tool. Developed
in early 1990s for handling traffic across a computer and network. It can be used to capture
specific events (such as a certain system call being invoked) or to monitor system performance
(such as time required to perform disk I/O). BCC package provides a number of existing tools
that monitor several areas of activity in a running Linux kernel. As an example, the BCC
‘disksnoop’ tool traces disk IO activity. Entering the command:
./disksnoop.py generates the following example output.
Shows the timestamp when the I/O operation occurred, whether the I.O was a Read or Write
operation, and how many bytes were involved in the I/O. the final column reflects the duration
(latency or LAT) in milliseconds.
For a particular process, we can use the command like:
./opensnoop –p 1225 trace open() system calls performed only by the process with an identifier.