What does a Operating System do?
Ressource Managment, Abstraction of Hardware ggf. user managemnt, visualization, IT security
How can OSs be classified?
By operating mode, by architecture, by purpose
How can OSs be classfied by Operating mode?
No OS -> non-programmable calculators, bootloader
Batch Processing -> Processes jobs in batches, no user interaction (e.g., early mainframes)
Interactive Systems ->User orientation, I/O, direct coupling of all devices
Distributed System -> Access via clients, Computers with networking, Servers service
Virtual Systems
How can OSs be classfied by architecture?
Monolithic
All OS functionalities are pooled in one large program
Operating System runs in the OS Mode of the processor
Applications run in the Application Mode of the processor
Microkernel
Operating System Core has minimal functionality
Only Core runs in OS Mode of the processor
Other Functions of OS and Applications run in the application mode of processor
Modular
Functionalities are (re-)loaded or unloaded on demand
How can OSs be classfied by Purpose?
1. Operating systems for mainframes
2. Server operating systems
3. PC operating systems
4. Multiprocessor/parallel computer operating systems
5. Realtime systems
6. Operating systems for embedded systems
What can be said about realtime systems?
In real-time operations, every programme has a starting point and deadline at which all its results must be computed. A real-time operating system ensures that:
• these deadlines are met through appropriate scheduling.
• error messages are generated if deadlines cannot be met.
• measures for minimising damage are taken if deadlines cannot be met
Can be further split into:
• Soft real-time
Missed deadlines lead to disadvantages which are called penalty. The operating system tries to minimise the level of penalty (amount and frequency).
• Hard real-time
Deadlines must not be missed. The result must be delivered before or at the latest at the deadline.
• Exact real-time
Deadlines must not be missed. The result must be delivered on the deadline.
Booatloader?
ROM fetches data and writes the memory block onto the RAM
for Hard Disks (Master Boot Record)
for partitions (Boot Sector / Boot Block)
Program within Boot Sector is started
Program turns off the ROM
Program loads the OS or Boot Manager and starts it Boot Manager, if required, selects the system to be booted, loads and starts it
What is a process?
Process is a program, which is being executed
Program is a file (source text file, program files in object code, program files in binary)
Multi-taksing vs Single-tasking?
Multi-tasking (Multiprogramming, Time-Sharing): Pseudo or actual simultaneous (parallel) execution of several processes.
Single-tasking:
Only exactly one process (job) can exist alongside the operating system.
How does the Process perspective differ from that of the OS/User?
How can a process be created?
By user request (starting an application)
System start
Batch job start
Running process request
What options exist for process creation by another process?
Process chaining:
The running process starts a new process and thus terminates itself. exec() UNIX
Process forking:
Running process starts a new process by creating a copy of itself fork()UNIX
Process ceation:
Running process starts an independent process
CreateProcess() Windows
Why is a process terminated?
Completed its task
Error
By OS due to critical error
By another process via system call (kill() and Terminate Process())
What options exist for process merging?
Process merging:
A process waits for a subordinate process to end (only in process hierarchy!)
Process rendezvous:
A process waits for any other process to end
Sketch an Extended Process State model
What states can a process exist in?
Running:
process is being executed, possesses the CPU
Ready:
Process can be executed but doesnt posses CPU
Blocked:
Process ist waiting for results, cant continue
New:
Process has been created, cant execute yet
Terminated:
Process has ended
What is a Process Table?
OS maintains Process Table to manage all processes. Single entry for process is called Process Control Block.
What is the Process Table used for?
The process table is the basis for scheduling. The process table can be consulted for monitoring tasks.
How is a process created using the Process Table by the OS?
Identifying an available process ID
Making known a new process to memory management.
− Creating memory management tables
− Initiating memory segment loading (Code, Heap, Stack)
Creating new PCB.
− Initialising the processor registers in the PCB (setup processor context)
− setting process state: initially New, then Ready
− assign first resources (e.g. stdin, stdout, stderr) Adding the PCB into the process table
What info is contained in a PCB?
Process identification
− Process ID (PID)
− Parent process (if process hierarchy, e.g. Unix) Process status information (for context switch)
− Register values
− Program counter (PC) and Processor Status Word (PSW)
− Stack pointer (SP)
Scheduling and state information
− Priorities
− Current process state (ready, blocked, running) Information for Inter-Process Communication (IPC)
Resources currently in use
− Opened files
− Devices currently in us
How can it be assured that processes dont effect each other?
Operating system and processes are executed on the same (physical) processor and are located in the same (physical) memory. It must be ensured that processes do not unintentionally affect each other or, most importantly, the operating system.
This requires hardware support:
The processor has at least 2 different privilege levels: − User mode
− Supervisor mode
The mode is stored/can be switched with the Process Status Word
Certain commands are executed by the (physical) processor only in the system mode.
− Reading/writing operating system management information
− Writing code into the memory
What are causes for a process switch?
System Call
process calls for OS functionality
Exception
hardware detects something unusual during process execution, leading to OS dealing with it l
Interrupt
ike exception, but triggered by external cause e.g. Polling / Strobing
How can a process switch look like?
Process A (A) is executed until an event triggers a process switch
Processor Context of A has to be saved
Memory Management is informed about switch
Process B context has to be loaded and continued
Whats the differnce between preemptive and cooperative multitasking?
Cooperative multitasking:
At some point, processes voluntarily transfer control to the operating system.
Problem: The application programmer must know and observe this “rule”.
Preemptive multitasking:
With the use of a timer and interrupt, a process cannot “defend itself” against having to transfer control to the operating system at some point.
What two general types of process communication exist?
Message based (both on the same computer and on different ones) and Memory based (memory coupling, same computer)
What categorization criteria exist for message based communication?
1.Data delimitation during communication
2.Synchronous communication
3.Connection orientation
4.Receiver addressing
How can data delimitation be categorized?
Data exchange with data streams
(streaming) (theoretically) unlimited data volume
Data exchange with messages
(message passing)
delimited data volume
volume has to be known to both sides during communication
Data exchange with packet
(packeting) using (fixed) standardized formats
What communication procedures exist?
Synchronous communication
(blocking)
Data are sent and received at the same time communication streams blocked until both parties are ready to receive/send data
Asynchronous communication
(non-blocking)
sending and receiving is independent blocking only occurs if buffer is empty, or buffer is full
What types of connection orientation exist?
Connection-oriented
connection channel is established
communication happens
channel is closed
Connection-less
no connection established
instead: message contains target address
What types of receiver adressing exist?
Unicast 1 sender – 1 receiver
Broadcast 1 sender – to all
Multicast 1 sender – x receiver (but not all)
Anycast 1 sender – to one out of a group of all
How does shared memory communication work?
How can a unnamed pipe be characterized and how is it differentiated from a named pipe?
Feature
Unnamed Pipe
Named Pipe (FIFO)
Visibility
Not visible in the file system
Appears as a file (special file type)
Creation
pipe() system call
pipe()
mkfifo() or mknod() system calls
mkfifo()
mknod()
Name/Path
No name, exists in memory only
Has a pathname in the filesystem
Directionality
Unidirectional
Unidirectional (but bidirectional can be simulated)
Communication
Between related processes (parent-child)
Between unrelated or related processes
Persistence
Exists only while processes are running
Exists until deleted, independent of process life
Scope
Local to processes that inherit file descriptors
Any process with access to the FIFO path
Common Use
Shell pipelines (`ls
grep`)
How do processes and threads differ?
A process
• owns resources
− has its own virtual address space
− “owns” virtual devices
− has privileges within the system
Thread can be a subunit for scheduling/execution
What is the main usage of threads?
Threads mainly used in parallel programming due to scheduling and the fact, that multiple threads can be within one process
What are the advatages of thread usage?
I/O devices only block one thread instead of the whole process
Shorter Response Time for user entries
Hyperthreading allows for parallel execution of multiple threads
What are the use cases of threads and processes?
Processes
Different tasks, which are independent and sporadicaly have to exchange data
e.g. Message Based
Threads
Different tasks, which heavily rely on the same data and have to exchange data or coordinate themselves very often
e.g. Memory Based Communication
What memory do threads share?
Threads within the same process share the same address space but have private stacks, registers and thread specific storage
What types of threads exist?
Aspect
Kernel Threads (KLT)
User Threads (ULT)
Management
Managed by the kernel
Managed by a user-level library
Scheduling
Scheduled by the kernel scheduler
Scheduled by user-space thread library
Blocking Behavior
If one thread blocks, others keep running
If one thread blocks, all may block (if not mapped to multiple kernel threads)
System Calls Needed
Requires system calls for creation, switching
No system calls; fast user-space switching
Performance (Context Switch)
Slower due to kernel involvement (mode switches)
Faster, purely in user space (no kernel mode switches)
Portability
OS dependent
More portable (independent of OS kernel)
Example APIs
POSIX Threads (pthreads on Linux, 1:1 model), Windows Threads
Java Green Threads (obsolete), user-mode threading libraries
Windows knows both variants; “thread” (kernel thread) and “fiber” (user thread)
What is the problem solved by synchronization?
When two processes/threads access and use the shared memory at the same time, the conten/results can drastically change.
What is the critical section in shared memory problems?
The section of the programm where shared ressources are accessed and/or modified.
Whats the idea behind mutual exclusion?
Only one process/thread should access shared ressources/be in the critical section at a time.
What requirements result from this mutual exclusion principle?
Requirement
Meaning
Mutual Exclusion
No two processes are in the critical section at the same time.
No assumptions about speeds
Your algorithm works regardless of process/thread speeds (asynchronous execution).
Progress
A process outside the critical section shouldn't block others unnecessarily.
Bounded Waiting
A process waiting to enter its critical section will eventually get in.
How can mutual exclusion be implemented?
1. Prevent interruption of a thread in the critical section
2. Software Solutions
3. Hardware supported Solutions
How can the interruption of a thread in the critical section be prevented?
disable interrupts generation in the processor when programm starts the critical section
only applicable in single processor systems -> other cpus could still access the critical section in multi core systems
OS loses control as preemptive multitasking is not possible
I/O depend on interupts
What software solutions exist and how do they work?
Peterson’s Algorith
Intention: A process sets flag[i] = true, signaling its intention to enter the critical section.
flag[i] = true
Turn Assignment: It sets turn = j, giving the other process priority if it also wants in.
turn = j
Wait Condition:
If the other process (j) doesn’t want in (flag[j] == false), you enter immediately.
j
flag[j] == false
If flag[j] == true, and it’s j's turn, you wait.
flag[j] == true
Critical Section: When the wait condition ends, you enter the critical section.
Exit: After leaving the critical section, you set flag[i] = false to indicate you’re done.
flag[i] = false
What does busy waiting mean?
the process/thread repeatedly queries the variable that protects the critical section. This is called a Spinlock.
• This consumes computing time. (State is always running)
• For scheduling procedures with priority, a deadlock may occur.
Explain CAS.
CAS is used to perform atomic updates on shared data in concurrent programming. It enables lock-free synchronization, preventing race conditions when multiple threads or processes access and modify shared memory.
CAS addresses the race condition problem that occurs when multiple threads attempt to update a shared variable simultaneously. It eliminates the need for traditional locking mechanisms (such as mutexes), reducing the risk of deadlocks and performance bottlenecks.
The CPU compares the current value at a specific memory location to an expected value.
If the current value matches the expected value, it is replaced with a new value.
If it does not match, the operation fails and typically retries.
The operation is atomic—no other thread can interrupt it during execution.
What are advatages and disadvantages of CAS?
Enables lock-free and wait-free algorithms.
Reduces overhead from context switching and locking.
Improves scalability and performance on multi-core processors.
Busy-waiting: Threads may repeatedly retry in high-contention situations, consuming CPU resources.
ABA problem: The memory value may change from A to B and back to A, misleading CAS into thinking no change occurred. Solutions require additional techniques like versioning.
Compare lock-based and lock-free approaches in general
Lock-Based
Lock-Free
Uses locks (flags, mutexes)
Uses atomic operations (CAS)
Threads may block or wait
Threads retry without blocking
Risk of deadlocks
No deadlocks
Easier to understand
More complex to design
May cause priority inversion
Avoids priority inversion
What is the advantage of Semaphores and Mutexes?
The previous correct solutions use busy waiting, i.e. the process/thread repeatedly queries the variable that protects the critical section. This is called a Spinlock.
• For scheduling procedures with priority, a deadlock may occur. Better idea:
1. If the process detects that the critical section is in use, it goes to “sleep“. (State: blocked)
2. A process/thread that leaves the critical section causes a sleeping process/thread to “wake up”. (State is again ready from then on)
Compare Semaphores and Mutexes in general.
Mutexes and semaphores are synchronization tools used to manage concurrent access to shared resources. Mutexes ensure mutual exclusion by allowing only one thread to lock a resource at a time. Semaphores use signaling to coordinate access, enabling multiple threads to share resources. While mutexes prevent race conditions, semaphores offer more flexibility. Choosing the right tool depends on the specific synchronization needs.
What synchronization types exist?
Lock and Sequence
Producer-Consumer Problem?
Producer-Consumer Problem Two threads share the same fixed-size buffer (N). One thread is the producer writing data to the buffer, the other thread is the consumer reading data from the buffer. Challenges:
1. No concurrent access to buffer management data. (Lock synchronisation)
2. The producer can only write if the buffer is not full. (Sequence synchronisation)
3. The consumer can only read if the buffer is not empty. (Seq. synchronisation)
Last changeda month ago