PowerPoint Presentation
Slide 1
Elements of an Operating System
Slide 2
Lecture Objective / Overview
In this lecture, we shall see:
◆ What happens when your computer starts
◆ The role of memory in a computer system
◆ How an OS manages multitasking
References:
Chapter # 1: Operating System Concepts (9th edition) by Silberschatz, Galvin & 3
Starting your Computer …
◆ A small bootstrap program is loaded when your
computer is started or rebooted
◼ Based on the saying “to pull oneself up by one’s bootstraps”
◼ A self-sustaining process that proceeds without external help
◆ First coined in 1953 by Computer Scientist when talking about the “self-loading procedure”
of the IBM Type 701 Computer
“The System Design of the IBM Type 701 Computer”
https://ieeexplore.ieee.org/document/4051191
https://ieeexplore.ieee.org/document/4051191
Slide 4
Starting your Computer …
◆ Stored in Read-Only Memory (ROM) or Electrically
Erasable Programmable Read-Only Memory (EEPROM).
◼Why? Can not be easily infected by a virus
◆ Known as firmware
◆ Initializes all aspects of the system:
◼ CPU registers
◼ Device controllers
◼ Memory contents
◆ Loads the operating system kernel into memory
Slide 5
Once the Firmware is loaded …
◆ Some services are provided outside of the kernel
◼These are loaded at boot time to become system processes
or system daemons
◼These run the entire time the kernel is running
◆ On UNIX, the first system process is “init”
◆ Once this is all loaded, the operating systems sits and
waits for events to occur…
Slide 6
Something happens …
◆ Examples: A user clicks a mouse or a program tries to
access a file
◆ These events are called interrupts
◼Can be triggered by hardware or software.
◆ Hardware may trigger an interrupt at any time by
sending a signal to the CPU
◆ Software triggers an interrupt by executing a special
operation
◼A system call
Slide 7
How does the CPU react?
◆ Stops what it is doing
◆ Immediately transfers execution to a fixed location
◆ This usually contains the starting address where the
service routine for the interrupt is located
◆ The interrupt service routine (ISR) executes
◆ On completion, the CPU resumes interrupted
computation
Slide 8
Interrupt Timeline
Slide 9
Memory
◆ An array of bytes, where each byte is addressable
◆ Read-only Memory (ROM)
◆ Electrically Erasable Programmable ROM (EEPROM)
◆ ROM cannot be modified
◼ Suitable for bootstrap programs and game cartridges(!)
◆ EEPROM can only be changed infrequently
◼ Most smartphones store factory-bundled programs on EEPROM
◆ CPU needs memory that it can read and write to
◼ Random-Access Memory (RAM)
◼ Implemented in a semiconductor technology called Dynamic RAM
(DRAM)
Slide 10
Register / Cache Memory
◆ Registers are another type of memory
◆ Main memory goes away when machine is switched off
◆ Secondary storage: magnetic disks, optical disks, tapes.
◆ Cache Memory:
◼ Data that has been used a lot is cached into a faster storage
system
◼ If CPU is looking for information, cache is first checked.
Slide 11
Multi-tasking in the CPU
◼CPU executes multiple jobs by switching between them
◼Switches occur so frequently that the users can interact with
each program while it is running
◼The KDF9 could handle up to 4 completely independent
programs at once!
Slide 12
Time Sharing
◆ Time sharing: Several jobs are kept simultaneously in
memory
◆ CPU Scheduling: Process of deciding which job is
brought to memory to be executed when space is an
issue
◆ Reasonable response time is of utmost importance:
◼Processes are swapped in and out of main memory to the
disk
◼Virtual memory is used. This technique allows the
execution of a process that is not completely in memory!
Slide 13
Time Sharing
◆ Virtual memory scheme enables users to run programs
that are larger than actual physical memory
◆ It abstracts main memory into a large, uniform array of
storage, separating logical memory as viewed by the
user from physical memory
◆ This frees programmers from concern over memory-
storage limitations!
Slide 14
OS Structure with Services
Slide 15
Dual Mode
User Mode
• user program executes in
user mode
• certain areas of memory are
protected from user access
• certain instructions may not
be executed
Kernel Mode
• monitor executes in kernel
mode
• privileged instructions may be
executed
• protected areas of memory
may be accessed
Slide 16
Why do we need Dual Mode?
◆ MS-DOS: Intel 8088 architecture which has no mode bit
◆ User program can therefore wipe out the whole OS
◆ Programs are able to write to a device
◆ In dual mode: Hardware detect errors that violate
modes and handle them with the help of OS
Slide 17
Why do we need Dual Mode?
◆ Stops user program attempting to execute an illegal
instruction or to access memory of other users
◆ When detected:
◼ OS must terminate the program
◼ OS gives error message
◼ Produces memory dumps by writing to a file.
Slide 18
System Calls
◆ System calls are the mechanism through which services
of the operating systems are sought.
◆ What language?
◼Typically C and C++
◼Sometimes assembly language
◼System call for reading data from one file and writing to
another file:
$ cp file1 file2
Slide 19
System Calls
◆ Open file1
◆ Possible error (print, abort)
◆ Create file2 (if exists, rewrite/rename)
◆ Start read and write (errors: diskspace, memory stick
unplugged)
◆ Read/write complete
◆ Close files
◆ Are these accessed directly? No – via API
$ cp file1 file2
Slide 20
Example of System Calls
System call sequence to copy the contents of one file to another file
Slide 21
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
Slide 22
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
Slide 23
Types of System Calls
❑ 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
Slide 24
Types of System Calls
❑ Protection
▪ Control access to resources
▪ Get and set permissions
▪ Allow and deny user access
Slide 25
Examples of Windows and Unix System Calls
Slide 26
System Calls : API Wrapper
◆ Application Programming Interface (API)
◆ Specifies a set of functions that are available to an
application programmer
◼ Includes the parameters passed to each function
◼Also includes the return values that the programmer can
expect
◆ Programmer accesses API via a library of code provided
by the OS
◆ Example: Windows API for Windows systems
◼ CreateProcess() invokes the NTCreateProcess() system call in
the Windows kernel. This returns values 0 or 1, if error thrown.
Slide 27
System Calls : API Wrapper
◆ POSIX API for POSIX-based systems (Portable Operating
System Interface) – UNIX, Linux & macOS X
◼Programmer accesses an API via a library of code provided by
the OS
◆ Example: read()
◆ Input:
◼ int fd: file descriptor to be read
◼ void *buf: pointer into buffer to be read into
◼ size_t count: maximum number of bytes to read
◆ Output:
◼ number of bytes read, if successful
◼ -1 if failed
Slide 28
System Calls : API Wrapper
Example:
◆ Java API for programs that run on the Java virtual
machine
◆ getParentFile()
◆ invoked on a file object
◆ Output:
◼Returns the abstract pathname of this file’s parent, or null if
this pathname does not name a parent directory.
◼ JVM uses the OS system calls.
Slide 29
Why use an API?
◆ Why not invoke system calls directly?
◼Program portability: program can compile and run on any
system that supports the API
◼System calls can often be more detailed and difficult to work
with
◼Give access to high level objects (Java API)
◆ For example, think of interfaces in Java
◆ Using system calls is like implementing an interface
Slide 30
Summary
What elements of the OS have we looked at?
◆ The Role of Memory
◆ Multitasking / Time Sharing
◆ System calls
◆ APIs