0% found this document useful (0 votes)
9 views

Unit-1_315b458c6da4f4ad3b52934054c48ff1

The document provides an overview of operating systems, detailing their roles, goals, types, and components. It discusses various operating system types, including batch, multi-programming, multi-processing, time-sharing, distributed, network, and real-time operating systems, along with their advantages and disadvantages. Additionally, it covers key components of operating systems such as process management, memory management, file management, and I/O subsystem management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Unit-1_315b458c6da4f4ad3b52934054c48ff1

The document provides an overview of operating systems, detailing their roles, goals, types, and components. It discusses various operating system types, including batch, multi-programming, multi-processing, time-sharing, distributed, network, and real-time operating systems, along with their advantages and disadvantages. Additionally, it covers key components of operating systems such as process management, memory management, file management, and I/O subsystem management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

CHAITANYA BHARATHI INSTITUTE OF TECHNOLOGY (A),

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.

Operating System Goals:


1. Execute user programs and make solving user problems easier
2. Make the computer system convenient to use
3. Use the computer hardware in an efficient manner

Computer System Structure:


1. Hardware – provides basic computing resources. Ex: CPU, memory, I/O devices
2. Operating System – controls and coordinates use of hardware among various
applications and users.
3. Application Programs- define the ways in which the system programs are used to
solve the computing problems of the users. Word processors, compilers, web browsers,
database systems, video games etc.
4. Users – people or entities who use computer. People, machines, other computers

Figure 1: Components of a Computer System


Figure 2: Computer Hardware

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.

Figure 3: Batch Operating System

Advantages of Batch Operating System


 Easy to implement
 Multiple users can share the batch systems.
 The idle time for the batch system is very less.
 It is easy to manage large work repeatedly in batch systems.

Disadvantages of Batch Operating System


 The computer operators should be well known with batch systems.
 Batch systems are hard to debug.
 It is sometimes costly.
 The other jobs will have to wait for an unknown time if any job fails.

Examples of Batch Operating Systems: Payroll Systems, Bank Statements, etc.

Multi-Programming Operating System: It allows to keep several programs in the main


memory and any one of them can be kept in execution. This is basically used for better
execution of resources.
Figure 4: Multi-Programming

Advantages:
 Multi Programming increases the Throughput of the System.
 It helps in reducing the response time.

Disadvantages of Multi-Programming Operating System


 There is not any facility for user interaction of system resources with the system.

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.

Multi-Tasking Operating System: is simply a multiprogramming operating system which


allocates the CPU among the processes in a Round-Robin fashion. It runs multiple programs
simultaneously. There are two types of Multi-Tasking systems:
 Pre-emptive Multi-Tasking
 Cooperative Multi-Tasking
Figure 6: Multitasking

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.

Figure 7: Time-Sharing Operating System

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.

Examples of Time-Sharing OS with explanation


 IBM VM/CMS: IBM VM/CMS is a time-sharing operating system that was first
introduced in 1972. It is still in use today, providing a virtual machine environment that
allows multiple users to run their own instances of operating systems and applications.
 TSO (Time Sharing Option): TSO is a time-sharing operating system that was first
introduced in the 1960s by IBM for the IBM System/360 mainframe computer. It
allowed multiple users to access the same computer simultaneously, running their own
applications.
 Windows Terminal Services: Windows Terminal Services is a time-sharing operating
system that allows multiple users to access a Windows server remotely. Users can run
their own applications and access shared resources, such as printers and network
storage, in real-time.

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

Advantages of Distributed Operating System


 Failure of one will not affect the other network communication, as all systems are
independent of each other.
 Electronic mail increases the data exchange speed.
 Since resources are being shared, computation is highly fast and durable.
 Load on host computer reduces.
 These systems are easily scalable as many systems can be easily added to the network.
 Delay in data processing reduces.

Disadvantages of Distributed Operating System

 Failure of the main network will stop the entire communication.


 To establish distributed systems the language is used not well-defined yet.
 These types of systems are not readily available as they are very expensive. Not only
that the underlying software is highly complex and not understood well yet.

Examples of Distributed Operating Systems are LOCUS, etc.

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

Advantages of Network Operating System

 Highly stable centralized servers.


 Security concerns are handled through servers.
 New technologies and hardware up-gradation are easily integrated into the system.
 Server access is possible remotely from different locations and types of systems.

Disadvantages of Network Operating System

 Servers are costly.


 User has to depend on a central location for most operations.
 Maintenance and updates are required regularly.

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.

Types of Real-Time Operating Systems


 Hard Real-Time Systems:
Hard Real-Time OSs are meant for applications where time constraints are very strict
and even the shortest possible delay is not acceptable. These systems are built for saving
life like automatic parachutes or airbags which are required to be readily available in
case of an accident. Virtual memory is rarely found in these systems.

 Soft Real-Time Systems


These OSs are for applications where time-constraint is less strict.

Figure 10: Real-Time Systems

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.

Examples: Scientific experiments, medical imaging systems, industrial control systems,


weapon systems, robots, air traffic control systems, etc.
Sources: https://www.geeksforgeeks.org/types-of-operating-systems/
Operating System Components:
1. Process Management
2. I/O Device Management
3. File Management
4. Network Management
5. Main Memory Management
6. Secondary Storage Management
7. Security Management
8. Command Interpreter System
Process Management:
 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.
 Process needs resources to accomplish its task
• CPU, memory, I/O, files
• Initialization data
 Process termination requires reclaim of any reusable resources
 Single-threaded process has one program counter specifying location of next
instruction to execute
• Process executes instructions sequentially, one at a time, until completion
 Multi-threaded process has one program counter per thread
 Typically system has many processes, some user, some operating system running
concurrently on one or more CPUs
• Concurrency by multiplexing the CPUs among the processes / threads
Process Management Activities: 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
 Providing mechanisms for deadlock handling

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

Mass Storage Management:


 Usually disks used to store data that does not fit in main memory or data that must be
kept for a “long” period of time
 Proper management is of central importance
 Entire speed of computer operation hinges on disk subsystem and its algorithms
 OS activities
• Mounting and unmounting
• Free-space management
• Storage allocation
• Disk scheduling
• Partitioning
• Protection

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)

Figure 12: Computer running a single OS and Three Virtual Machines

Operating System Services: OS provides an environment for execution of programs and


services to programs and users.
Services useful for users: These services include:
 User Interface (UI): almost all operating systems have a UI. This varies between
Command-Line Interface (CLI), Graphical User Interface (GUI), Touch-screen,
Voice-based, Batch etc.
 Program Execution: Operating System must be able to load a program into
memory and to run that program, end execution, either normally or abnormally
(indicating error).
 I/O operations: A running program may require I/O, which may involve a file or
an I/O device.
 File-System manipulation: Programs need to read and write files and directories,
create and delete them, search them, list file information, and permission
management.
 Communication: Processes may exchange information, on the same computer of
between computers over a network. This ca be done by using shared memory,
message passing and sockets.
 Error Detection: Operating System must be aware of possible errors.
o May occur in the CPU and memory hardware, in I/O device, or in user
program
o For each type of error, OS should take the appropriate action to ensure
correct and consistent computing.
o Debugging facilities can greatly enhance the user’s and programmer’s
abilities to efficiently use the system
Services provided for efficient system operation
 Resource Allocation: When multiple users or multiple jobs running concurrently,
resources must be allocated to each of them. These resources are: CPU cycles, main
memory, file storage, I/O devices.
 Logging: To keep track of which users use how much and what kinds of computer
resources.
 Protection & Security: The owners of information stored in a multiuser or
networked computer system may want to control the use of that information,
concurrent processes should not interfere with each other. Protection involves in
ensuring all access to system resources is controlled. Security of the system from
outsiders require user authentication, extends to defending external I/O devices
from invalid access attempts.

Figure 13: An overview of Operating System Services

Command Line Interpreter (CLI):


 Allows users to access utilities.
 Primarily fetches a command from user and executes it.
 Sometimes implemented in kernel, sometimes by systems program.
 Sometimes multiple flavors implemented – shells
 Sometimes commands built-in, sometimes just names of programs where here adding
new features doesn’t require shell modification
 Different Shells in Linux
• C Shell (csh - /bin/csh – University of California), C like syntax,
• Bourne Shell (/bin/sh – AT&T Bell Labs), faster, lacks few features, default
shell for Solaris OS.
• Korn Shell (ksh - /bin/ksh – AT&T Bell written by David Korne), superset of
Bourne shell. Compatible to C shell
• Borne-Again Shell (bash - /bin/bash) -
• T Shell (tsh - ) – Plan 9 OS, ported to Linux, FreeBSD, and MacOS
• Z Shell (zsh) – Paul Falstad, a student of Princeton University in 1991, extended
version of bash.

Graphical User Interface:


 User-friendly desktop metaphor interface
• Usually mouse, keyboard, and monitor
• Icons represent files, programs, actions, etc
• Various mouse buttons over objects in the interface cause various actions
(provide information, options, execute function, open directory (known as a
folder)
• Invented at Xerox PARC
 Many systems now include both CLI and GUI interfaces
• Microsoft Windows is GUI with CLI “command” shell
• Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and
shells available
• Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME)

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:

fd: file descriptor;


buf: a character buffer in to which the data read
count: No. of bytes to be read
size_t: No. of bytes read

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).

Figure 15: Passing parameters as table

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.

Process Control System Calls:


 Create process, terminate process
 End, abort
 Load, execute
 Get process attributes, set process attributes
 Wait for time, wait event, signal event
 Allocate memory and free memory
 Dump memory if error
 Debugger for determining bugs, single step execution
 Locks for managing access to shared data between process
 Examples of Linux System Calls: fork(), exec(), exit(), wait, waitpid(),sleep(),
signal(),alrm(), shmget(),shmctl(), pause(),kill() etc.
File Management system Calls
 Create file, delete file
 Open, close file
 Read, write, reposition
 Get and set file attributes
Device Management System Calls
 Request device, release device
 Read, write, reposition
 Get device attributes, set device attributes
 Logically attach or detach devices
Information Maintenance System Calls
 Get time or date, set time of date
 Get system data, set system data
 Get and set process, file, or device attributes
Communications
 Create, delete communication connection
 Send, receive messages if message passing model to host name or process
name
 Shared memory model create and gain access to memory regions
 Transfer status information
 Attach and detach remote devices
Protection
 Control access to resources
 Get and set permissions
 Allow and deny user access
Example: Arduino
 Single-tasking
 No operating system
 Programs (sketch) loaded via USB into flash memory
 Single memory space
 Boot loader loads program
 Program exit -> shell reloaded

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

Linkers and Loaders:


 Source code compiled into object files
designed to be loaded into any physical
memory location – relocatable object file
 Linker combines these into single binary
executable file
• Also brings in libraries
 Program resides on secondary storage as
binary executable
 Must be brought into memory by loader to be
executed
• Relocation assigns final addresses to
program parts and adjusts code and
data in program to match those
addresses
 Modern general purpose systems don’t link
libraries into executables
• Rather, dynamically linked libraries Figure 16: Role of linker and loader
(in Windows, DLLs) are loaded as
needed, shared by all that use the same version of that same library (loaded
once)
 Object, executable files have standard formats, so operating system knows how to
load and start them
Design and Implementation of Operating System
 Design and Implementation of OS is not “solvable”, but some approaches have proven
successful
 Internal structure of different Operating Systems can vary widely
 Start the design by defining goals and specifications
 Affected by choice of hardware, type of system
 User goals and System goals
• User goals – operating system should be convenient to use, easy to learn,
reliable, safe, and fast
• System goals – operating system should be easy to design, implement, and
maintain, as well as flexible, reliable, error-free, and efficient
 Specifying and designing an OS is highly creative task of software engineering
 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

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

Operating System Structure: Several approaches


 General-purpose OS is very large program – Monolithic structure
 Various ways to structure ones
• Simple structure – MS-DOS
• More complex – UNIX
• Layered – an abstraction
• Microkernel – Mach
Monolithic Structure – Original UNIX:
 UNIX – limited by hardware functionality, the original UNIX operating system had
limited structuring.
 The UNIX OS consists of two separable parts
• Systems programs
• The kernel
 Consists of everything below the system-call interface and above the
physical hardware
 Provides the file system, CPU scheduling, memory management,
and other operating-system functions; a large number of functions
for one level
Traditional UNIX System Structure: Its design is beyond simple, but not fully
layered.

Figure 17: Traditional UNIX Structure

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)

Figure 19: Linux System Structure

Figure 20: Block Diagram of Windows System

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

Modular System Structure:


 Many modern operating systems implement loadable kernel modules (LKMs)
• Uses object-oriented approach
• Each core component is separate
• Each talks to the others over known interfaces
• Each is loadable as needed within the kernel
 Overall, similar to layers but with more flexible
• Linux, Solaris, etc.

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.

Android: was designed by the Open-Handset Alliance


(led primarily by Google) and was developed for
Android smartphones and tablet computers, whereas
iOs is designed to run on Apple mobile devices and is
closed-sourced. Android runs on a variety of mobile
platforms and is open-sourced.
Android is similar to iOS that it is a layered software
that provides a rich set of frameworks and tools
 Supporting graphics, Audio, Hardware features
and also
 Platform to develop applications that run on a
multitude of Android-enabled devices
 ART VM: a VM designed for Android and
optimized for mobile devices with limited
memory and CPU processing capabilities.
 Java Native Interface (JNI): allows developers
to bypass VM and the programs can access
specific hardware features.
 Native libraries (SQLite, openGL, webkit,
surface manager, SSL, media framework
 Hardware Abstraction Layer (HAL) Figure 22: Architecture of Google Android

 Bionic- Google C library for Android


 Linux Kernel – Google has modified the Linux kernel on Android in variety of
areas to support the special needs of mobile systems, such power management,
memory management and allocation and has added a new form of IPC known
as Binder.
Building and Booting Operating System
OS Generation: to generate from the scratch, follow the steps of:
1. Write the operating system source code (or obtain previously written source code)
2. Configure the operating system on which it will run (system build).
3. Compile the operating system.
4. Install the operating system.
5. Boot the computer and its new operating system.
Linux System building: Steps to build a Linux system from the scratch are:
1. Download the Linux source code from http:www.kernel.org.
2. Configure the kernel using “mak menuconfig” command. It will generates the ‘.config’
configuration file.
3. Compile the main kernel using the “make” command. The ‘make’ command compiles
the kernel based on the configuration parameters identified in the ‘.config’, producing
the file ‘vmlinuz’, which is the kernel image.
4. Compile the kernel modules using “make modules” command.
5. Use the command “make modules-install” to install the kernel modules into ‘vmlinuz’.
6. Install the new kernel on the system by the “make install” command.
When the system reboots, it will begin running this new operating system.

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.

Figure 23: BCC and eBPF tracing tools

You might also like