Chapter 2: Operating-System
Structures
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 2: Operating-System Structures
Operating System Services
User Operating System Interface
System Calls
Types of System Calls
System Programs
Operating System Design and Implementation
Operating System Structure
Operating System Debugging
Operating System Generation
System Boot
Operating System Concepts – 9th Edition 2.2 Silberschatz, Galvin and Gagne ©2013
Objectives
To describe the services an operating system provides to
users, processes, and other systems
To discuss the various ways of structuring an operating
system
To explain how operating systems are installed and
customized and how they boot
Operating System Concepts – 9th Edition 2.3 Silberschatz, Galvin and Gagne ©2013
Operating System Services
Operating systems provide an environment for execution of programs
and services to programs and users
One set of operating-system services provides functions that are
helpful to the user:
User interface - Almost all operating systems have a user
interface (UI).
Varies between Command-Line (CLI), Graphics User
Interface (GUI), Batch(commands in files)
Program execution - The system must be able to load a
program into memory and to run that program, end execution,
either normally or abnormally (indicating error)
I/O operations - A running program may require I/O, which may
involve a file or an I/O device
For efficiency and protection, users cannot directly control I/O
devices.
Operating System Concepts – 9th Edition 2.4 Silberschatz, Galvin and Gagne ©2013
A View of Operating System Services
The "System Calls" layer is a critical bridge. Since applications are not
allowed to touch the hardware directly (for security and stability reasons),
they must send a "System Call" to the OS to request resources, such as
reading a file or printing a document.
Operating System Concepts – 9th Edition 2.5 Silberschatz, Galvin and Gagne ©2013
Operating System Services (Cont.)
File-system manipulation - The file system is of particular interest.
Programs need to read and write files and directories, create and delete
them, search them, list file Information, permission management.
Communications – Processes may exchange information, on the same
computer or between computers over a network
Communications may be via shared memory or through message
passing
Error detection – OS needs to be constantly aware of possible errors
May occur in the CPU and memory hardware(memory error, power
failure), in I/O devices(connection failure in network, paper lack in
printer), in user program(arithmetic overflow, access to illegal
memory location)
For each type of error, OS should take the appropriate action to
ensure correct and consistent computing
Debugging facilities can greatly enhance the user’s and
programmer’s abilities to efficiently use the system
If an app crashes, the OS stays alive; if the OS crashes (e.g., a "Blue Screen of Death"), the entire system halts.
Operating System Concepts – 9th Edition 2.6 Silberschatz, Galvin and Gagne ©2013
Operating System Services (Cont.)
Another set of OS functions exists for ensuring the efficient operation of the
system itself via resource sharing
Resource allocation - When multiple users or multiple jobs running
concurrently, resources must be allocated to each of them
Many types of resources - CPU cycles, main memory, file storage,
I/O devices.
Accounting - To keep track of which users use how much and what
kinds of computer resources
Protection and security - The owners of information stored in a
multiuser or networked computer system may want to control use of
that information, concurrent processes should not interfere with each
other
Protection involves ensuring that all access to system resources is
controlled
Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access
attempts
Operating System Concepts – 9th Edition 2.7 Silberschatz, Galvin and Gagne ©2013
1-User Operating System Interface - CLI
CLI or command interpreter(shell) allows direct command entry
a shell is a user interface for access to an operating
system's services.
Sometimes implemented in kernel, sometimes by systems
program (Windows and UNIX, treat the command
interpreter as a special program
that is running when a job is initiated or when a user first
logs on (on interactive systems)).
Sometimes multiple flavors implemented – shells
Most shells provide similar functionality.
[Link]
shells
Primarily fetches a command from user and executes it
Many of commands at this level manipulate files: create,
delete, list, print, copy, execute etc
Operating System Concepts – 9th Edition 2.8 Silberschatz, Galvin and Gagne ©2013
windows Shell Command Interpreter
Command Prompt, a CLI shell in Windows
• The command interpreter itself contains the code to
execute the command
• Alternative approach: implement most commands through
system programs (Used by Unix)
• rm [Link] Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition 2.9
2-User Operating System Interface - GUI
User-friendly desktop metaphor interface
Mouse based windows and menu’s characterized by a
desktop metaphor(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) or pull down a
menu(contains commands)
Unix→ Common desktop environment(CDE), X windows
System,K desktop Environment(KDE) GNOME are GUI based
MAC OS X→ GUI based
Microsoft’s first version of Windows—Version 1.0—was based
on the addition of a GUI interface to the MS-DOS operating
system (Later versions→ Cosmetic changes in appearance
and functionality).
Operating System Concepts – 9th Edition 2.10 Silberschatz, Galvin and Gagne ©2013
Operating System Services
Operating System Concepts – 9th Edition 2.11 Silberschatz, Galvin and Gagne ©2013
Touchscreen Interfaces
n Touchscreen devices require new
interfaces
l Mouse not possible or not desired
l Actions and selection based on
gestures
l Virtual keyboard for text entry
l Voice commands.
Operating System Concepts – 9th Edition 2.12 Silberschatz, Galvin and Gagne ©2013
Choice of Interface
n The choice of whether to use a command-line or GUI interface is mostly
one of personal preference.
n System administrators who manage computers and power users who have
deep knowledge of a system frequently use the command-line interface.
l more efficient, giving them faster access to the activities they need to
perform.
l only a subset of system functions is available in some systems via the
GUI, leaving the less common tasks to those who are command-line
knowledgeable .
l Command line interfaces usually make repetitive tasks easier, in part
because they have their own programmability.
Scalability & Bulk Actions: If you need to rename 5,000 text files, move them to a new directory, and then zip them, a
single line of Bash code will do in 2 seconds what a GUI would take an hour to do
Remote Server Work: Most high-performance computing (HPC) clusters or Cloud GPUs (AWS/Azure) do not have a
monitor attached. You must use a CUI (via SSH) to interact with them.
Operating System Concepts – 9th Edition 2.13 Silberschatz, Galvin and Gagne ©2013
The Mac OS X GUI
n Mac OS has not provided a command-line interface.
n Mac OS X (which is in part implemented using a UNIX kernel), the
operating system now provides both a Aqua interface and a
command-line interface
Operating System Concepts – 9th Edition 2.14 Silberschatz, Galvin and Gagne ©2013
System Calls
n Programming interface to the services provided by the OS
n System calls are the interface through which an application program
interacts with the operating system kernel.
n They are functions or routines provided by the operating system that allow
user-level processes or applications to request services from the operating
system.
n Typically written in a high-level language (C or C++)
n Systems can execute thousands of system calls per second
l writing a simple program to read data from one file and copy them to
another file.
n Programmers never see this level of detail
The Kernel (The Core)
The kernel is the most essential part of the operating system. It is the first program loaded when the computer starts and it stays in the main memory (RAM)
until the computer is turned off.
Operating System Concepts – 9th Edition 2.15 Silberschatz, Galvin and Gagne ©2013
System Calls
n Designs programs via a high-level Application Programming
Interface (API) rather than direct system call use
n The API specifies a set of functions available to an application
programmer(including the parameters passed to the programs and
return values)
n Three most common APIs are Win32 API for Windows, POSIX API
for POSIX-based systems (including virtually all versions of UNIX,
Linux, and Mac OS X), and Java API for the Java virtual machine
(JVM)
n A programmer accesses an API via a library of code provided by
the operating system. In the case of UNIX and Linux for programs
written in the C language, the library is called libc.
n Behind the scene→ function typically invoke actual system call on
behalf of application programmer.
APIs are for developers to talk to software, while System Calls are for software to talk to the hardware.
Operating System Concepts – 9th Edition 2.16 Silberschatz, Galvin and Gagne ©2013
Example of System Calls
n System call sequence to copy the contents of one file to another file
Operating System Concepts – 9th Edition 2.17 Silberschatz, Galvin and Gagne ©2013
System Calls
n Createprocess() function of win32 API actually calls
NTCreateProces()
n Why application programmer prefer programming according to API
rather than direct system call?
l Program portability
l Actual system calls are more detailed and difficult to work
with than an API available.
Operating System Concepts – 9th Edition 2.18 Silberschatz, Galvin and Gagne ©2013
Example of Standard API
Operating System Concepts – 9th Edition 2.19 Silberschatz, Galvin and Gagne ©2013
System Call Implementation
n Typically, a number associated with each system call
l System-call interface maintains a table indexed according to
these numbers
n The system call interface invokes the intended system call in OS
kernel and returns status of the system call and any return values
n The caller need know nothing about how the system call is
implemented
l Just needs to obey API and understand what OS will do as a
result call
l Most details of OS interface hidden from programmer by API
Managed by run-time support library (set of functions built
into libraries included with compiler)
Operating System Concepts – 9th Edition 2.20 Silberschatz, Galvin and Gagne ©2013
API – System Call – OS Relationship
Operating System Concepts – 9th Edition 2.21 Silberschatz, Galvin and Gagne ©2013
System Call Parameter Passing
n Often, more information is required than simply identity of desired
system call
l Exact type and amount of information vary according to OS
and call
n Three general methods used to pass parameters to the OS
l Simplest: pass the parameters in registers
In some cases, may be more parameters than registers
l Parameters stored in a block, or table, in memory, and
address of block passed as a parameter in a register
This approach taken by Linux and Solaris
l Parameters placed, or pushed, onto the stack by the program
and popped off the stack by the operating system
l Block and stack methods do not limit the number or length of
parameters being passed
Operating System Concepts – 9th Edition 2.22 Silberschatz, Galvin and Gagne ©2013
Parameter Passing via Table
Operating System Concepts – 9th Edition 2.23 Silberschatz, Galvin and Gagne ©2013
Types of System Calls(six categories)
System calls can be grouped roughly into six major categories:
n Process control
n file manipulation
n device manipulation
n information maintenance
communications
n protection
Operating System Concepts – 9th Edition 2.24 Silberschatz, Galvin and Gagne ©2013
Types of System Calls(six categories)
1-Process control
l create process, terminate process
l end, abort
l load, execute
l get process attributes, set process attributes
l wait for time
l wait event, signal event
l allocate and free memory
l Dump memory if error
l Debugger for determining bugs, single step execution
l Locks for managing access to shared data between processes(shared
data.).
acquire lock() and release lock().
Operating System Concepts – 9th Edition 2.25 Silberschatz, Galvin and Gagne ©2013
Types of System Calls(six categories)
Process Control example
Operating System Concepts – 9th Edition 2.26 Silberschatz, Galvin and Gagne ©2013
Types of System Calls
2-File management
l create file, delete file
l open, close file
l read, write, reposition
l get and set file attributes
Operating System Concepts – 9th Edition 2.27 Silberschatz, Galvin and Gagne ©2013
Types of System Calls
3-Device management
l request device, release device
l read, write, reposition
l get device attributes, set device attributes
l logically attach or detach devices
Operating System Concepts – 9th Edition 2.28 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
4-Information maintenance
l get time or date, set time or date
l get system data, set system data
l get and set process, file, or device attributes
Operating System Concepts – 9th Edition 2.29 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
5-Communications
l create, delete communication connection
l send, receive messages
l transfer status information
l attach and detach remote devices
Operating System Concepts – 9th Edition 2.30 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
5-Communications
l Two mechanisms
l 1: Message passing Model: messages can be exchanged
between processes either directly or indirectly through a
common mailbox.
A connection must be opened.
Name of communicators must be known, be it another
process on same computer or a process on another
computer connected through network.
Host name, network identifier(IP)(Hostid and process id by
system calls) These identifiers then passed to open and
close calls.
– Get_hostid(), get_processid() do this translation
– Identifiers are passed to open() and close() calls
– Or to open_connection and close_connection system
call.
The recipient process must gives its permission
(accept_connection)
Operating System Concepts – 9th Edition 2.31 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
5-Communications(contd..)
read message() and write message() system calls.
The close connection() call terminates the communication.
2: Shared Memory Model:
l Processes used shared_memory_create() and
shared_memory_ attach() system call to create and gain
access to regions of memory owned by other processes.
l Shared memory requires that two processes agrees to
remove the restriction of not sharing each other memory.
l Read and write data in the shared area.(not under the control
of OS… determined by processes)
l These processes are responsible for not overwriting the
same location simultaneously.
Operating System Concepts – 9th Edition 2.32 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
5-Communications(contd..)
l Message passing is useful for exchanging small amount of
data.
Easier to implement
l Shared memory allows maximum speed and convenience of
communication(can be done at memory transfer speed)
l Problems exist, however, in the areas of protection and
synchronization between the processes sharing memory
Operating System Concepts – 9th Edition 2.33 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
5-Communications(contd..)
Protection Problems
Shared memory allows multiple processes to access the same
memory space. Without protection mechanisms:
• Unauthorized Access: Any process might read or write to
memory it shouldn't, leading to data breaches or corruption.
• Memory Overwrites: One process could accidentally or
maliciously overwrite data being used by another.
• Segmentation Faults: Improper access (like accessing
deallocated memory) can cause crashes.
n Solution: Use memory protection features (like page
permissions), operating system-level access controls, or memory
sandboxing.
Operating System Concepts – 9th Edition 2.34 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
5-Communications(contd..) Synchronization Problems:
Since multiple processes are accessing the same data, coordination
is crucial. Without proper synchronization:
• Race Conditions: Two processes may try to read and write at the
same time, causing unpredictable behavior.
• Deadlocks: Processes waiting on each other’s actions might get
stuck forever.
• Inconsistency: Partial updates by one process could be read by
another, resulting in corrupt or incorrect data.
Solution: Use synchronization primitives like:
• Semaphores
• Mutexes
• Locks
• Monitors
n These ensure that only one process can access critical sections of
memory at a time.
Operating System Concepts – 9th Edition 2.35 Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation
n Internal structure of different Operating Systems can vary widely
n Start the design by defining goals and specifications
n Affected by choice of hardware, type of system
l Choice of Hardware: CPU Architecture (x86, ARM, RISC-V),
Number of CPUs/Cores, Memory Capacity and Type, I/O Devices
(disks, keyboards, GPUs), Power Constraints (mobile devices)
l Type of Systems: Batch System, Time-sharing System, Real Time
systems, Embedded System, Mobile OS, Distributed OS
n The requirements can, however, be divided into two basic groups:
user goals and system goals.
n User goals and System goals
l User goals – operating system should be convenient to use, easy to
learn, reliable, safe, and fast (these specifications are not particularly
useful in the system design )
l System goals – operating system should be easy to design, implement,
and maintain, as well as flexible, reliable, error-free, and efficient
Operating System Concepts – 9th Edition 2.36 Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation (Cont.)
n Important principle to separate
Policy: What will be done?
Mechanism: How to do it?
For example, the timer construct is a mechanism for ensuring
CPU protection, but deciding how long the timer is to be
set for a particular user is a policy decision.
n Mechanisms determine how to do something, policies decide
what will be done
n The separation of policy from mechanism is a very important
principle, it allows maximum flexibility if policy decisions are to
be changed later (example – timer)
l each change in policy would require a change in the
underlying mechanism
Operating System Concepts – 9th Edition 2.37 Silberschatz, Galvin and Gagne ©2013
Implementation
n Much variation
l Early OSes in assembly language
l Then system programming languages like PL/1
l Now C, C++
n Actually usually a mix of languages
l Lowest levels in assembly
l Main body in C
l Systems programs in C, C++, scripting languages like PERL,
Python, shell scripts
n More high-level language easier to port to other hardware
Reading Assignment:
Difference between high level and
low level programming languages
Operating System Concepts – 9th Edition 2.38 Silberschatz, Galvin and Gagne ©2013
Operating System Structure
n General-purpose OS is very large program
l Partition the task into smaller components rather than
monolithic system
l These modules should be well defined(defined inputs,
outputs and functions)
n Various ways to structure ones
l Simple structure – MS-DOS
l More complex -- UNIX
l Layered – an abstrcation
l Microkernel –Mach
l Hybrid
Operating System Concepts – 9th Edition 2.39 Silberschatz, Galvin and Gagne ©2013
Simple Structure -- MS-DOS
MS-DOS – written to provide the
most functionality in the least
space
Operating System Concepts – 9th Edition 2.40 Silberschatz, Galvin and Gagne ©2013
Non Simple Structure -- 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
almost all the OS was in one big layer, not really
breaking the OS down into layered subsystems
Monolithic approach
Operating System Concepts – 9th Edition 2.41 Silberschatz, Galvin and Gagne ©2013
Traditional UNIX System Structure
Beyond simple but not fully layered
Operating System Concepts – 9th Edition 2.42 Silberschatz, Galvin and Gagne ©2013
Layered Approach
The operating system is divided into a
number of layers (levels), each built on
top of lower layers. The bottom layer
(layer 0), is the hardware; the highest
(layer N) is the user interface.
With modularity, layers are selected
such that each uses functions
(operations) and services of only lower-
level layers
The main advantage is simplicity of
construction and debugging.
The main difficulty is defining the
various layers.
The main disadvantage is that the OS
tends to be less efficient than other
implementations.
Each layer adds overhead to the system call;
the net result is a system call that takes
longer than does one on a non-layered
system
Operating System Concepts – 9th Edition 2.43 Silberschatz, Galvin and Gagne ©2013
Layered Approach
Operating System Concepts – 9th Edition 2.44 Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
Operating System Concepts – 9th Edition 2.45 Silberschatz, Galvin and Gagne ©2013
Microkernel System Structure
Application File Device user
Program System Driver mode
messages messages
Interprocess memory CPU kernel
Communication managment scheduling mode
microkernel
hardware
Operating System Concepts – 9th Edition 2.46 Silberschatz, Galvin and Gagne ©2013
Modules
Operating System Concepts – 9th Edition 2.47 Silberschatz, Galvin and Gagne ©2013
Modules
How Modular approach is different from Microkernel?
Core Kernel: Handles essential tasks but is larger than a microkernel,
including some built-in services.
Loadable Modules: Modules (e.g., drivers, network protocols) are
loaded into kernel space, sharing the same privilege level as the core
kernel.
Direct Interaction: Modules can call each other or the core kernel
directly, avoiding message-passing overhead.
Operating System Concepts – 9th Edition 2.48 Silberschatz, Galvin and Gagne ©2013
Solaris Modular Approach
Operating System Concepts – 9th Edition 2.49 Silberschatz, Galvin and Gagne ©2013
Hybrid structure
A hybrid kernel is an operating system kernel architecture that
attempts to combine aspects and benefits
of microkernel and monolithic kernel architectures used
in computer OS.
The idea behind a hybrid kernel is to have a kernel structure
similar to that of a microkernel, but to implement that structure
in the manner of a monolithic kernel.
Prominent example of a hybrid kernel is the Microsoft Windows
NT kernel.
All operating systems in the Windows NT family, up to and
including Windows 10 and Windows Server 2016, and powers
Windows Phone 8, Windows Phone 8.1 use hybrid kernel.
Operating System Concepts – 9th Edition 2.50 Silberschatz, Galvin and Gagne ©2013
Hybrid Systems
Most modern operating systems are actually 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 OS X hybrid, layered, Aqua UI plus Cocoa
programming environment
Below is kernel consisting of Mach microkernel and BSD Unix
parts, plus I/O kit and dynamically loadable modules (called
kernel extensions)
Operating System Concepts – 9th Edition 2.51 Silberschatz, Galvin and Gagne ©2013
Mac OS X Structure
graphical user interface
Aqua
application environments and services
Java Cocoa Quicktime BSD
kernel environment
BSD
Mach
I/O kit kernel extensions
Operating System Concepts – 9th Edition 2.52 Silberschatz, Galvin and Gagne ©2013
End of Chapter 2
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013