Professional Documents
Culture Documents
Structures
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 2: Operating-System Structures
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
What is an
Operating System
Operating System Concepts – 9th Edition 2.4 Silberschatz, Galvin and Gagne ©2013
What is an Operating System (OS)?
● Depends on the point of view Should have been called
Operating Management
System
● A program that acts as the management of the entire system
● A program that acts as an intermediary between a user of a computer and the
computer hardware
● A program that provides basic facilities for the rest of the system
● Operating system goals:
● Execute user programs and make solving user problems easier
● Make the computer system convenient to use
● Use the computer hardware in an efficient manner
Operating System Concepts – 9th Edition 2.5 Silberschatz, Galvin and Gagne ©2013
System view of Operating Systems
● No universally accepted definition
● Operating System (OS) - a set of programs that manage computer hardware resources
and provide common services for application software
● “The one program running at all times on the computer” is the kernel
● OS is a resource allocator
● Manages all resources
● Decides between conflicting requests for efficient and fair resource use
● OS is a control program
● Controls execution of programs to prevent errors and improper use of the computer
● Agreement on… The management of three major areas of concern
Operating System Concepts – 9th Edition 2.7 Silberschatz, Galvin and Gagne ©2013
Computer System Layered Structure
● Computer system can be divided into four components:
● Hardware – provides basic computing resources
o CPU, memory, I/O devices
● Operating system
o Controls and coordinates use of hardware among various applications
and users
● Application programs – define the ways in which the system resources are
used to solve the computing problems of the users
o Word processors, compilers, web browsers, database systems, video
games
● Users
o People, machines, other computers
Operating System Concepts – 9th Edition 2.8 Silberschatz, Galvin and Gagne ©2013
Four Layers of a Computer System
Operating System Concepts – 9th Edition 2.9 Silberschatz, Galvin and Gagne ©2013
OS Services
and
Functions
Operating System Concepts – 9th Edition 2.10 Silberschatz, Galvin and Gagne ©2013
Operating System Services & Management Functions
System User
Batch Command GUI programs applications
Line
O/S User Interface
System Calls
Main &
Program File I/O device Communication
secondar Services
execution y Systems Operations s
Memory
Process Mgt Storage Mgt I/O Mgt
Operating System
Hardware
Operating System Concepts – 9th Edition 2.11 Silberschatz, Galvin and Gagne ©2013
Operating System Services
Main &
Program File I/O device Communication
secondar Services
execution y Systems Operations s
Memory
Process Mgt Storage Mgt I/O Mgt
● One set of operating-system services provides functions that are helpful to the user:
● 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)
● Memory & 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
● I/O operations - A running program may require I/O, which may involve a file or an
I/O device
● Communications – Processes may exchange information:
4 Locally - on the same computer using Inter Process Communication (IPC) through
shared memory or message passing
4 Remotely - between computers over a network – through message passing (packets
moved by the OS over networks using network protocols)
Operating System Concepts – 9th Edition 2.12 Silberschatz, Galvin and Gagne ©2013
Operating System management functions
● 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
4 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
Operating System Concepts – 9th Edition 2.13 Silberschatz, Galvin and Gagne ©2013
Operating System management functions
Operating System Concepts – 9th Edition 2.14 Silberschatz, Galvin and Gagne ©2013
Operating System Interface
● Application programming interface (API) – intended to be used from within a program and is
based on system calls usually provided through libraries
● There are two generic types of access that use the Application programming interface (API) :
● User (or management) access – through a user interface – used for:
4 System management
4 Software development purposes
● User/System programs access – intended to be used from programs that require OS services
Application
programming
interface (API)
Hardware
Operating System Concepts – 9th Edition 2.15 Silberschatz, Galvin and Gagne ©2013
User Interfaces
Operating System Concepts – 9th Edition 2.16 Silberschatz, Galvin and Gagne ©2013
User Interfaces
● One set of programs that are related to the management and use of the OS are
user interfaces
● User interface - Almost all operating systems have a user interface (UI).
Varies between
4 Batch
4 Command-Line (CLI)
4 Graphics User Interface (GUI)
4 Voice activated
Operating System Concepts – 9th Edition 2.17 Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - CLI
Operating System Concepts – 9th Edition 2.18 Silberschatz, Galvin and Gagne ©2013
Bourne Shell Command Interpreter
To examine which interpreter:
$ echo $SHELL
/bin/bash
To get a list of all bash commands:
$ help
It is important to distinguish the interpreter commands from real
executables
Operating System Concepts – 9th Edition 2.19 Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - GUI
Operating System Concepts – 9th Edition 2.20 Silberschatz, Galvin and Gagne ©2013
Touchscreen Interfaces
Operating System Concepts – 9th Edition 2.21 Silberschatz, Galvin and Gagne ©2013
The Mac OS X GUI
Operating System Concepts – 9th Edition 2.22 Silberschatz, Galvin and Gagne ©2013
System Interface:
System Calls + API
Operating System Concepts – 9th Edition 2.23 Silberschatz, Galvin and Gagne ©2013
System Calls
● The services and management functions provided by the OS are not accessed
directly from user code. Normal subroutine calls will not do as they do not change
the user->kernel mode
● They can only be accessed using system calls – these are wrapped by library
functions (defined by the Application Programming Interface) that prepare the
data for a system call and ultimately perform a system call
● OS services or management functions are accessed by programs via a high-level
Application Programming Interface (API) rather than direct system call use
Operating System Concepts – 9th Edition 2.25 Silberschatz, Galvin and Gagne ©2013
API – System Call – OS Relationship
Application Program
Kernel
Services
Operating System Concepts – 9th Edition 2.26 Silberschatz, Galvin and Gagne ©2013
Application Programming Interface
● Typically written in a high-level language (C or C++)
● Three most common APIs are
● Win32 API for Windows
4 The Windows API, informally WinAPI, is Microsoft's core set of application
programming interfaces available in the Microsoft Windows operating
systems
4 The library's wrapper functions expose an ordinary function calling
convention (a subroutine call on the assembly level) for using the system call,
as well as making the system call more modular
Operating System Concepts – 9th Edition 2.28 Silberschatz, Galvin and Gagne ©2013
Example of the use of System Calls
● System call sequence to copy the contents of one file (source) to another file
(destination)
copy
Operating System Concepts – 9th Edition 2.29 Silberschatz, Galvin and Gagne ©2013
Example of System Calls
#include <stdio.h>
#include <stdlib.h>
if(argc!=3) {
printf("Usage: copy <source> <destination>\n");
exit(1);
}
if(fclose(from)==EOF) {
printf("Error closing source file.\n");
exit(1);
Operating System Concepts – 9th Edition 2.30 Silberschatz, Galvin and Gagne ©2013
}
System Call Implementation
Wrapping
● Typically, a number associated with each system call hardware
● System-call interface maintains a table indexed according to specific
calls -
these numbers Allows
● The system call interface invokes the intended system call in OS standards
to evolve
kernel and returns status of the system call and any return values
● The caller need know nothing about how the system call is
implemented
● Just needs to obey API and understand what OS will do as a
result call
● Most details of OS interface hidden from programmer by API
4 Managed by run-time support library (set of functions built
into libraries included with compiler)
Operating System Concepts – 9th Edition 2.31 Silberschatz, Galvin and Gagne ©2013
System Call Parameter Passing
Operating System Concepts – 9th Edition 2.32 Silberschatz, Galvin and Gagne ©2013
Parameter Passing via Table
Could also be a pointer to a
table with the parameters
System Call
Application Kernel
Operating System Concepts – 9th Edition 2.33 Silberschatz, Galvin and Gagne ©2013
Types of System Calls
● Process control
● create process, terminate process
● end, abort
● load, execute
● get process attributes, set process attributes
● wait for time
● wait event, signal event
● allocate and free memory
● dump memory if error
● Debugger for determining bugs, single step execution
● Locks for managing access to shared data between processes
Operating System Concepts – 9th Edition 2.34 Silberschatz, Galvin and Gagne ©2013
Types of System Calls
● File management
● create file, delete file
● open, close file
● read, write, reposition
● get and set file attributes
● Device management
● request device, release device
● read, write, reposition
● get device attributes, set device attributes
● logically attach or detach devices
Operating System Concepts – 9th Edition 2.35 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
● Information maintenance
● get time or date, set time or 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
4 From client to server
● Shared-memory model create and gain access to memory regions
● transfer status information
● attach and detach remote devices
Operating System Concepts – 9th Edition 2.36 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
● Protection
● Control access to resources
● Get and set permissions
● Allow and deny user access
Operating System Concepts – 9th Edition 2.37 Silberschatz, Galvin and Gagne ©2013
Examples of Windows and Unix System Calls
Operating System Concepts – 9th Edition 2.38 Silberschatz, Galvin and Gagne ©2013
Examples of Windows and Unix System Calls
Operating System Concepts – 9th Edition 2.40 Silberschatz, Galvin and Gagne ©2013
System Programs
System User
Batch Command GUI programs applications
Line
O/S User Interface
System Calls
Main &
Program File I/O device Communications
secondar Service
execution y Systems Operations s
Process Mgt Memory
Storage Mgt I/O Mgt
Operating System Concepts – 9th Edition 2.42 Silberschatz, Galvin and Gagne ©2013
System Programs
● Provide a convenient environment for program development and
execution
● Some of them are simply user interfaces to system calls; others are
considerably more complex
● File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories
● Status information
● Some ask the system for info - date, time, amount of available
memory, disk space, number of users
● Others provide detailed performance, logging, and debugging
information
● Typically, these programs format and print the output to the terminal
or other output devices
● Some systems implement a registry - used to store and retrieve
configuration information
Operating System Concepts – 9th Edition 2.43 Silberschatz, Galvin and Gagne ©2013
System Programs (Cont.)
● File modification
● 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
Operating System Concepts – 9th Edition 2.44 Silberschatz, Galvin and Gagne ©2013
System Programs (Cont.)
● Background Services
● Launch at boot time
4 Some for system startup, then terminate
4 Some from system boot to shutdown
● Provide facilities like disk checking, process scheduling, error logging,
printing
● Run in user context not kernel context
● Known as services, subsystems, daemons
● Application programs
● Are not system programs
● Run by users
● Not typically considered part of OS
● Launched by command line, mouse click, finger poke
Operating System Concepts – 9th Edition 2.45 Silberschatz, Galvin and Gagne ©2013
Operating System
Design and
Implementation
Operating System Concepts – 9th Edition 2.46 Silberschatz, Galvin and Gagne ©2013
Operating System Design and Implementation
Operating System Concepts – 9th Edition 2.47 Silberschatz, Galvin and Gagne ©2013
Design principle: separating policy from mechanism
Operating System Concepts – 9th Edition 2.48 Silberschatz, Galvin and Gagne ©2013
Example: MS-DOS
● Single-tasking
● Shell invoked when system
booted
● Simple method to run program
● No process created
● Single memory space
● Loads program into memory,
overwriting all but the kernel
● Program exit -> shell reloaded
Operating System Concepts – 9th Edition 2.49 Silberschatz, Galvin and Gagne ©2013
Example: FreeBSD (Berkeley Software Distribution)
● Unix variant
● Multitasking
● User login -> invoke user’s choice of shell
● Shell executes fork() system call to create
process
● Executes exec() to load program into
process
● Shell waits for process to terminate or
continues with user commands
● Process exits with:
● code = 0 – no error
● code > 0 – error code
Operating System Concepts – 9th Edition 2.50 Silberschatz, Galvin and Gagne ©2013
Operating-System
Debugging & Tuning
Operating System Concepts – 9th Edition 2.51 Silberschatz, Galvin and Gagne ©2013
Operating-System Debugging
● Debugging is finding and fixing errors, or bugs
● OS generate log files containing error information
● Failure of an application can generate core dump file capturing memory of the
process
● Operating system failure can generate crash dump file containing kernel
memory
● Beyond crashes, performance tuning can optimize system performance
● Sometimes using trace listings of activities, recorded for analysis
● Profiling is periodic sampling of instruction pointer to look for statistical
trends
Kernighan’s Law: “Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition,
not smart enough to debug it.”
Operating System Concepts – 9th Edition 2.52 Silberschatz, Galvin and Gagne ©2013
Performance Tuning
Operating System Concepts – 9th Edition 2.53 Silberschatz, Galvin and Gagne ©2013
Strace
Strace is a system call tracer. It is used to reverse engineer executables behaviour. Used in Linux.
$ strace /bin/ls
execve("/bin/ls", ["/bin/ls"], [/* 66 vars */]) = 0 The shell launches the program
brk(NULL) = 0x238f000 brk is the low-level for real memory allocation for code and data
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 ld.so.cache holds the path for each library in the OS
fstat(3, {st_mode=S_IFREG|0644, st_size=187261, ...}) = 0 Verify access to ld.so.cache
mmap(NULL, 187261, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f21848d1000 Read ld.so.cache content
close(3) = 0 Close ld.cache.so file
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3 Open security library required by /bin/ls
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260Z\0\0\0\0\0\0"..., 832) = 832 and read it
fstat(3, {st_mode=S_IFREG|0644, st_size=130224, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f21848d0000
mmap(NULL, 2234080, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f21844b8000
mprotect(0x7f21844d7000, 2093056, PROT_NONE) = 0 mprotect defines a segment in the memory to none accessible.
mmap(0x7f21846d6000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e000) = 0x7f21846d6000
mmap(0x7f21846d8000, 5856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f21846d8000 mmap is the way to allocate
memory
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory
...
Operating System Concepts – 9th Edition 2.54 Silberschatz, Galvin and Gagne ©2013
System Boot
● When power initialized on system, execution starts at a
CPU
fixed memory location
● Firmware ROM used to hold initial boot code Main Memory
● Operating system must be made available to hardware so Bootstrap
code
hardware can start it
● Small piece of code – bootstrap loader, stored in
ROM or EEPROM locates the kernel, loads it into
memory, and starts it
● Sometimes two-step process where boot block at
fixed location loaded by ROM code, which loads
bootstrap loader from disk
● Common bootstrap loader, GRUB, allows selection of
kernel from multiple disks, versions, kernel options
● Kernel loads and system then starts running
Operating System Concepts – 9th Edition 2.55 Silberschatz, Galvin and Gagne ©2013
End of Chapter 2
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013