Concepts Flashcards
What is an Operating System?
An operating system is the one program running at all times on a computer (called the kernel) that manages a computer’s hardware. Everything else is either a system or application program.
First 3 OS phases?
Serial Processing → Simple Batch Systems → Multi-programmed Batch Systems
Why is an Operating System likened to a government?
Because, like a government, it can’t execute a useful function on its own, but can create an environment within which other programs can execute them.
How does an OS act as an intermediary between a user and computer hardware?
An OS acts as an intermediary by acting as a manager of these resources and controlling and allocating resources. A computer’s resources refer to its hardware such as CPU time, memory space, I/O devices (for e.g. printer, keyboard, mouse). The OS must decide how to allocate these to specific programs and users so it can operate the computer system efficiently.
What do System Calls do?
Provide an interface to the services made available by an operating system.
Why would an application programmer prefer programming according to
an API rather than invoking actual system calls?
Because an API can specify a set of functions and parameters for the programmer, and actual systems. Direct systems calls require more integration effort because all integration logic has to be manually coded.
What is the microkernel approach, and why was it developed?
As an OS expanded, it became difficult to manage. Microkernel removes all nonessential components from a kernel and implementing them as system and user-level programs. This results in smaller kernels, requiring less processes and memory management.
One pro and con of the microkernel approach.
Pro: The resulting OS is easier to port from one hardware design to another. The microkernel also provides more security and reliability, since most services are running as user—rather than kernel— processes. If a service fails, the rest of the operating system remains untouched.
Con: Performance of microkernels can suffer due to increased system-function overhead (slower processing speed, less memory, etc).
What is the Modules approach?
Involves using loadable kernel modules for an OS design - so the kernel has it’s core functions, and then other additional functions are added dynamically.
Why is the Modules Approach similar but better than the Microkernel Approach?
Like the microkernel approach, the primary module has only core functions, but it also has nonessential modules added as layers. This means modules do not need to invoke message passing up and down those layers to communicate.
What are hybrid systems? Provide examples with reasoning.
In reality, most OS combine different structures to address performance, security and usability issues.
For example, Linux and Solaris are monolithic - where all core components are in one place - which provides efficient performance. However, they are also modular, so that new functionality can be dynamically added to the kernel.
What is the definition of a process?
A program in execution / a program that’s been activated.
How does an OS execute a program (to turn it into a process)?
By loading the program into memory
What is a process made up of (in memory)?
text (the code), data (global and static variables), heap (memory dynamically allocated during run time), stack (keeps track of active function calls)
What 2 parts of a process grow toward each other?
The stack grows downward in memory, whilst the heap grows up in memory.
What happens when the heap and stack overlap?
The program could crash, but the OS monitors this to avoid a collision.
What different states can a process be in during execution?
New (process is being created)
Running (executing)
Waiting (for an event)
Ready (to be assigned)
Terminated (finished)
What is a Process Control Block (PCB)?
A structure that contains all the information about a process:
Process state
Program counter
CPU registers
Scheduling Info
Memory-management info
I/O status
In brief what does a PCB serve as?
A repository for any information that may
vary from process to process.
What is a thread when compared to processes?
A process is a container for threads - one single process can have one or multiple threads of execution, allowing a process to perform more than one task at a time.
Benefits of multithreading?
1) Responsiveness - let’s a program keep running even if one thread is busy or blocked.
2) Threads share the memory and resources of the process by default - no need for message passing.
3) More economical if resources are being shared
What is a context switch?
When CPU switches to another process, the system must SAVE the
state of the old process (in the PCB) and LOAD the saved state of the new process - aka, a context switch
What is process creation?
A process may create several new processes, like how a parent would create children.
What 2 options are there for parent/child process execution?
- The parent and children process execute concurrently.
- The parent waits until children have terminated.
Can a child process share resources with parent resource?
Yes and no - they may be able to, or may be constrained to a subset of resources.
Can processes communicate with one another?
Yes. this is called Inter-Process Communication (IPC) which allows processes to work together
How can they communicate?
Using a) message passing or b) shared memory.
Message passing may either be… a or b
a) blocking (synchronous) or
b) non-blocking (asynchronous)
What is an independent vs cooperating process?
An independent process executes without affecting or being affected by other processes.
Cooperating process - the opposite.
What is concurrency?
Where multiple programs can be executed simultaneously.
What is a race condition?
When multiple processes access and manipulate the same data concurrently and the outcome of the execution depends on an order of the order of the execution.
What aims to guard against race conditions occurring?
Process Synchronisation - they have to be in some way, to ensure only one process can manipulate data at a time.
What is the critical-section problem?
When 2 or more processes are executing in their critical-sections simultaneously.
What 3 requirements must be satisfied for a solution to the critical-section problem?
1) Must be mutually exclusive
2) Progress - can’t prevent other processes from entering their critical-section when no process is executing theirs.
3) Bounded Waiting - limit on number of times other processes are allowed to enter their critical-sections AFTER a process has made a request to enter its critical section, and BEFORE that request is granted.
What is Peterson’s solution to the critical-section problem?
Processes A and B have their own lock + a mask for their locks.
A arrives at critical region first, sets its lock, pushes mask to the other lock and enters.
B arrives and sets its lock and pushes its mask, but must wait until A’s lock is reset.
A exits CR and resets its lock - B can now enter.
Does Peterson’s solution to the critical-section problem work?
Yes, in pure software - but not guaranteed to work on modern computer architectures - too much overhead.
What’s the Test-Set-Lock (TSL) solution?
Helps us build a shared lock mechanism.
A reaches CR, finds a key and takes it.
B arrives, sees no key, waits.
A leaves CR, key returned to start.
B can now take the key and enter.
Test-set-lock is similar to the speaker’s baton…
Only one person can hold it at a time
Pro and con of test-set-lock solution?
Pro: Mutual exclusion is achieved.
Con: Bounded waiting and progress are NOT GUARANTEED, also requires special hardware.
What is an atomic instruction?
An operation that is indivisible - either completes fully, or doesn’t happen. like a light switch - either ON or OFF, never inbetween.
How does atomic instruction help in the critical-section problem - use a real world analogy.
Imagine signing a form at a reception desk. You can only do it if no one else is already writing. An atomic instruction is like locking the pen and clipboard to your hand until you’re done — nobody else can mess with it
What’s a mutex lock (mutual exclusion lock)?
Where a process must acquire the lock before entering the critical-section. Releases the lock when it leaves the critical-section.
Main disadvantage of mutex lock?
Requires busy waiting - other processes not in the critical-section must loop continuously, wasting CPU cycles.
TF is a Semaphore?
A more sophisticated approach to process synchronisation.
It’s a special integer value, only accessible through 2 atomic operations: wait() and signal().
What do the atomic operations wait and signal do to a semaphore?
Wait() decrements the value - if semaphore value becomes negative, process becomes blocked.
Signal() increments - if semaphore becomes positive, it can unblock a previously blocked process.
Pro and con of semaphore
Pro: ensures mutual exclusion, can cause synchronisation in multiple processes, effective for signalling between processes (like saying ‘I’m done, your turn’)
Con: incorrect use of signal() can cause deadlocks, resource leaks.
Can cause spinlocks (busy waiting), wasting CPU cycles.
Detail one classic problem of synchronisation.
SINGLE LANE BRIDGE.
A road is only wide enough for one way traffic at a time.
Cars can move concurrently if moving in same direction.
Deadlock: Without proper synchronisation, cars from both directions block each other.
Starvation: favouring one side can starve the other.
What is CPU Scheduling?
Allowing one process to use the CPU whilst another is waiting for I/O, making use of lost CPU cycles.