Lecture 2
Lecture 2
Programming
Moumen El-Melegy
Professor of Computer Engineering
Electrical Engineering Department
Assiut University, Assiut 71516
[email protected]
https://sites.google.com/site/EC427Spring20/
EC 427
4th Year, Computer & System Eng.
Operating System Concepts – 9th Edition 1.1 Silberschatz, Galvin and Gagne ©2013
Lecture 2
Computer System
Architecture
Operating System Concepts – 9th Edit9on Silberschatz, Galvin and Gagne ©2013
Computer System Structure
Operating System Concepts – 9th Edition 1.3 Silberschatz, Galvin and Gagne ©2013
Computer Startup
Operating System Concepts – 9th Edition 1.4 Silberschatz, Galvin and Gagne ©2013
Interrupts
Operating System Concepts – 9th Edition 1.5 Silberschatz, Galvin and Gagne ©2013
Interrupt Handling
Operating System Concepts – 9th Edition 1.6 Silberschatz, Galvin and Gagne ©2013
I/O Structure
Synchronous I/O: After I/O starts, control returns to user
program only upon I/O completion
Wait instruction idles the CPU until the next interrupt
Wait loop (contention for memory access)
At most one I/O request is outstanding at a time, no
simultaneous I/O processing
Asynchronous I/O: After I/O starts, control returns to user
program without waiting for I/O completion
System call – request to the OS to allow user to wait for
I/O completion
Device-status table contains entry for each I/O device
indicating its type, address, and state
OS indexes into I/O device table to determine device
status and to modify table entry to include interrupt
Operating System Concepts – 9th Edition 1.8 Silberschatz, Galvin and Gagne ©2013
I/O Structure
Operating System Concepts – 9th Edition 1.9 Silberschatz, Galvin and Gagne ©2013
Hardware Protection
Operating System Concepts – 9th Edition 1.10 Silberschatz, Galvin and Gagne ©2013
Dual-Mode Operation
Operating System Concepts – 9th Edition 1.12 Silberschatz, Galvin and Gagne ©2013
Memory Protection
Operating System Concepts – 9th Edition 1.13 Silberschatz, Galvin and Gagne ©2013
CPU Protection
Timer to prevent infinite loop / process hogging resources
Timer is set to interrupt the computer after some time period
Keep a counter that is decremented by the physical clock.
Operating system set the counter (privileged instruction)
When counter zero generate an interrupt
Set up before scheduling process to regain control or
terminate program that exceeds allotted time
Operating System Concepts – 9th Edition 1.14 Silberschatz, Galvin and Gagne ©2013
Chapter 2: Operating-System
Structures
Operating System Concepts – 9th Edit9on Silberschatz, Galvin and Gagne ©2013
System Components
Process Management
Memory Management
Storage Management
I/O Management
Protection and Security
Networking
Command-Interpreter System
Operating System Concepts – 9th Edition 1.17 Silberschatz, Galvin and Gagne ©2013
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
Operating System Concepts – 9th Edition 1.18 Silberschatz, Galvin and Gagne ©2013
Process Management Activities
Operating System Concepts – 9th Edition 1.19 Silberschatz, Galvin and Gagne ©2013
Memory Management
Operating System Concepts – 9th Edition 1.20 Silberschatz, Galvin and Gagne ©2013
Storage 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
Operating System Concepts – 9th Edition 1.23 Silberschatz, Galvin and Gagne ©2013
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
Operating System Concepts – 9th Edition 1.24 Silberschatz, Galvin and Gagne ©2013
Command Interpreter System
Operating System Concepts – 9th Edition 1.26 Silberschatz, Galvin and Gagne ©2013
User Operating System Interface - GUI
Operating System Concepts – 9th Edition 1.27 Silberschatz, Galvin and Gagne ©2013
Touchscreen Interfaces
Operating System Concepts – 9th Edition 1.28 Silberschatz, Galvin and Gagne ©2013
The Mac OS X GUI
Operating System Concepts – 9th Edition 1.29 Silberschatz, Galvin and Gagne ©2013
System Calls
Programming interface to the services provided by
the OS
Typically written in a high-level language (C or C++)
Mostly accessed by programs via a high-level
Application Programming Interface (API) rather
than direct system call use
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)
Operating System Concepts – 9th Edition 1.30 Silberschatz, Galvin and Gagne ©2013
Example of System Calls
System call sequence to copy the contents of one file to another file
Operating System Concepts – 9th Edition 1.31 Silberschatz, Galvin and Gagne ©2013
API – System Call – OS Relationship
Operating System Concepts – 9th Edition 1.32 Silberschatz, Galvin and Gagne ©2013
System Call Parameter Passing
Operating System Concepts – 9th Edition 1.33 Silberschatz, Galvin and Gagne ©2013
Parameter Passing via Table
Operating System Concepts – 9th Edition 1.34 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 1.35 Silberschatz, Galvin and Gagne ©2013
Types of System Calls (Cont.)
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 1.36 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
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 1.37 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 1.38 Silberschatz, Galvin and Gagne ©2013
Examples of Windows and Unix System Calls
Operating System Concepts – 9th Edition 1.39 Silberschatz, Galvin and Gagne ©2013
Standard C Library Example
C program invoking printf() library call, which calls write() system call
Operating System Concepts – 9th Edition 1.40 Silberschatz, Galvin and Gagne ©2013