Introduction Flashcards
modern computer layout
hardware + software
-> software = kernel mode (OS) + user mode (UI + apps)
operating system
a program that manages the hardware
basis for apps
intermediary between user and hardware
os as a resource manager
top-down view
-> provides abstractions to apps
bottom-up view
-> manages pieces of complex systems
-> provides orderly, controlled allocation of resources
1st generation of OSs
(1945-55): Vacuum tubes
second generation of OSs
(1955-65): Transistors and batch systems
3rd generation of OSs
(1965-1980): ICs and multiprogramming
4th generation of OSs
(1980-present): Personal computers
5th generation of OSs
(1990-present): Mobile computers
UNIX, MINIX, LINUX
UNIX - a simpler os
- MINIX (1980s)
- LINUX (1990s)
Each component of a computer has a …
controller
three stage pipeline
Fetch -> Decode -> Execute
memory hierarchy
registers
cache
main memory
magnetic disk / SSD
up: size and access time decrease, cost increases
volatile memory
gone when the system doesn’t have power
registers <-> cache
quick access <-> slower access
nonvolatile storage
a type ofcomputer memory that can retain stored information even after power is removed
SSD
Solid State Drive
- No moving parts, data in electronic(flash) memory
- Much faster than magnetic disks
I/O devices strcuture
controller + device
device driver
- OS component that talks to controller
- One for each type of device controller
- communicates with controller via registers
- either accessed using special instructions (e.g., IN/OUT) or mapped in the OS’ address space (the addresses it can use)
I/O Port Space
The collection of device registers
to perform I/O:
- process executes system call
- kernel makes a call to driver
- driver starts I/O and either polls device to see if it is done (busy waiting) or asks device generate an interrupt when it is done (and returns) more advanced: make use of special hardware – DMA
interrupt
the occurrence of an event usually signalled by an Interrupt from Hardware or Software
CPU interrupted → stops what it is doing and transfers execution to a fixed location → the interrupt service routine executes → CPU resumes the interrupted action
hardware <-> software interrupts
hardware → interrupt
software → system call
bootstrap program
- the initial program that runs when a computer is powered up or rebooted
- it is stored in the ROM
- it must know how to load the OS and start executing that system
- it must locate the OS kernel and load it into memory
- in ROM form, because RAM is in an unknown state at startup
booting
the procedure of starting a computer by loading the kernel
booting steps
- firmware: ROM memory
- EPROM (erasable programmable ROM)
- flash memory on motherboard contains firmware (aka BIOS)
- after pressing power button, CPU executes BIOS which:
- initialises RAM and other resources
- scans PCI/PCIe buses to initialise devices
- sets up the runtime firmware for critical services (e.g. low-level I/O) to be used by the system after booting
- BIOS looks for location of partition table on second sector of boot device
- contains locations of other partitions
- BIOS can read simple file systems (e.g. FAT-32), and starts first bootloader program (from partition indicated by UEFI boot manager)
- the bootloader may load other bootloader programs
- eventually the OS is loaded
Computer System Architecture based on number of general purpose processors
- single processor systems
- one main CPU executing the general purpose instruction set + special purpose processors
- multiprocessor systems
- multiple CPUs
- clustered systems
- grouped systems
The OS Zoo
- Mainframe Operating Systems
- Server Operating Systems
- Personal Computer Operating Systems
- Smartphone and Handheld Computer Operating Systems
- The Internet of Things (IOT) and Embedded Operating Systems
- Real-Time Operating Systems
- Smart Card Operating Systems
What is an OS?
- extended machine
- Extending the hardware functionality
- Abstraction over hardware
- Hiding details from the programmer
- resource manager
- Protects simultaneous/unsafe usage of resources
- Fair sharing of resources
- Resource accounting/limiting
processes
user-level abstractions to execute a program on
behalf of a user
- Each process has its own address space
- Data involved in this processing is retrieved from/stored in files
- Files persist over processes
services
groups of system calls
multiprogramming
increases CPU utilisation by making sure it is always in use by some user
time sharing (multitasking)
CPU switches among jobs(occurs so quickly that the users can interact with each program while it is running); uses CPU scheduling and multiprogramming
OS Services
- user interface
- program execution
- I/O operations
- file system manipulation
- communications
- error detection
- resource allocation
- accounting(keeping track of users’ usage of resources)
- protection and security
User OS Interface
- allows users to interact with the system
- approaches:
- CLI (Command-Line-Interface)
- GUI - most common
- in some systems the command interpreter is in the kernel, while in others it is treated as a special program (interpreter-shell)
process
a program in execution
Address space affected by:
architecture
OS
program
Address space layout
stack: active call data
data: program variables
text: program code
OS’ process table
keeps information about processes
suspended process
consists of process table entry(saved registers and other info needed to restart the process) and its address space
file
an abstraction of possibly real storage devices
maintained in directories
root directory
/
absolute path <-> relative path
/home/ast/todo-list
../courses/slides1.pdf
files are “protected” by
three bit tuples for owner, group and other users
Tuples contain a (r)ead, (w)rite and an e(x)ecute bit
special files
hardware devices
symbolic links
named/anonymous FIFOs (sockets/pipes)
pipes
pseudo files allowing for multiple processes to communicate over a FIFO channel
Ontogeny Recapitulates Phylogeny
Each new “species” of computer goes through same development as “ancestors”
system calls
the interface the OS offers to applications to issue service requests
function call <-> system call
function call: libraries - apps
system call: OS - libraries
fork()
create a child process identical to parent
waitpid(…)
waitpid(pid, &statloc, options)
wait for a child to terminate
execve(…)
execve(name, argv, environp)
replace a process’ core image
exit(…)
exit(status)
terminate process execution and return status
return codes
pid - process id
fd - file descriptor
n - byte count
position - offset within the file
seconds - elapsed time
lseek()
move the file pointer
monolithic os structure
- system call: a computer program’s way of requesting a service from the kernel
- kernel in monolithic block with service procedures and utility procedures
service and utility procedures
service procedures: carry out the system calls
utility procedures: help implement service procedures
layered os structure
separate apps and os using 2 privilege levels: user and kernel
layered os levels
0 kernel
1 sys calls
2 shared libraries
3 user
kernel mode
crash ->entire system crash
user mode
no direct access to memory and hardware
safe
context switching
- switching between modes
- when user need access to resources
- user makes system call when it needs to switch
Which layers can use each other?
a layer can use only the ones below
- exokernel
- unikernel
- allocates resources to virtual machines and then check attempts to use them to make sure no machine is trying to use somebody else’s resources
- minimal LibOS-based sys- tems that contain just enough functionality to support a single application (such as a Web server) on a virtual machine
unikernel
- Modern incarnation of LibOS
- Just enough functionality to support a single application (e.g., Web server)
- Often on top of VMOnly one application on VM all code can run in kernel mode
Microkernel-based Client/Server
- Organise service procedures in programs that run in separate processes →
System Servers/Drivers - idea: remove all the nonessential components from the kernel and implement them as programs
- System processes communicate via message passing
- System calls rely on the same messaging mechanism
- achieve high reliability by splitting the operating system up into small, well-defined modules, only one of which—the microkernel—runs in kernel mode and the rest run as relatively pow- erless ordinary user processes
microkernel +/-
+ easier to adhere to Principle of Least Authority (POLA)
+ Relatively small Trusted Computing Base (TCB)
+ Each OS process allowed to do only what is needed to perform its task
+ Compromise of, say, the printer driver will not affect rest of the OS
- Message passing is slower than a function call (as in a monolithic kernel)
build process for c
file1.c + file2.c… -> preprocessor -> compiler -> file1.o, libc.a -> linker -> a.out (executable binary)
LINUX system calls
- triggered by special instruction (- Privilege level is changed to kernel mode
- Program counter is set to specific location)
- arguments for syscalls are passed in registers
pid_t fork()
- Duplicates the current process
- Returns child pid in caller (parent)
- Returns 0 in new (child) process
pid_t wait(int *wstatus)
- Waits for child processes to change state
- Writes status to wstatus
- E.g., due to exit or signal
int execv(const char *path, char *constargv[])
- Loads a new binary (path) in the current process, removing all other memory mappings
- constargv contains the program arguments
- Last argument is NULL
- E.g., constargv = {“/bin/ls”, “-a”, NULL}
signal
sent to the process that needs to be interruptedi
Interrupted process can catch the signal by installing a
signal handler
CTRL+C
SIGINT
terminates the process
CTRL+Z
SIGTSTP
suspends the process and puts it in the background
sighandler_t signal(int signum, sighandler_t handler)
Registers a signal handler for signal signum
unsigned int alarm(unsigned int seconds)
Deliver SIGALRM in specified number of seconds
int kill(pid_t pid, int sig)
Deliver signal sig to process pid