layer of software, providing applications access to the underlying hardware resources
Manages access to resources most efficiently
controls the exectution of programmes, enforces oritection and isolation between processes
Endianness
Big-endian: Most significant bytes first
Little-endian: Least significant bytes first
CPU Registers
General purpose Registers: storing immediate values and memory addresses
Control Registers: for status flags
Instuction point registers: Program counter
OS Protection Boundary
Modern CPUS have two modes
kernel mode: privileged operations possible (privilege bit has to be set)
user mode: normal mode for standart operations
Intel CPU has more than two modes (rings) Kernel, Drivers, Drivers, Applications. each with different reights
System Calls
a programm can use a system call to request a service from the kernel
hardware related services(e.g., access to a hard disk)
creation and execution of new processes
communication with process scheduling
Example: read(): process calls syscall wrapper function read() -> wrapper function places system call number 0 in accumulator register RAX and parameters in designated registers -> wrapper function calls trap function to generate software interrupt -> Processor switches to kernel mode, invokes syscall dispatcher -> dispatcher looks up the syscall handler corresponding to the syscall number from the syscall table -> syscall handler processes the syscall -> Control is returned to the calling wrapper function, processor retuns to user mode
What is a Process
abstraction of a running programme
consists of static code and data
Process States
Process Control Block (PCB)
holds informatino descirbing the process' state
-> all the information neccessary for restart of stopped process
program counter, register contents, stack pointer, memeory allocations, open files, accounting information, scheduling information
Multiprogramming
multiple processes run on a system in "parallel"
each process has own virtual CPU
CPU rapidly switches between processes -> illusion of parallelism (switch called: context switch)
Process Creation
POSIX = Portable Operating System Interface
Vorgehen:
fork(): syscall creates identical copy of process
returns P_ID of the child, in the child, 0 is returned, -1 for error
exec(): syscall to replace child memory space with new programme
wait(): parent process can wait until child finishes
Process Creation
exit(): syscall terminates programm
kill(): parent terminates child
Process Memory Segments
text: read only, "the programm"
data: static initialized data
created and set bevore execution
bss: uninitialized data
created bevore execution: static int x;
stack: LIFO, grows down
implicit use: int y = 3;
heap: FIFO, grows up
use with malloc
Stack for Function Call
divided into frames: Each frame is segment of stack associated with one call to one function
containts function arguments, local variables, return address
call function_name: adds return address to the stack
ret: pops the return address of stack, loads to instuction pointer (EIP)
Inter-Process Communication (IPC)
Inter-Process Communication (IPC)
message passing-based IPC
send() adds message to message queue
receive() read message from message queue
shared memory-based IPC
memory region mapped into virtual memory of both processes