Exam1 more Flashcards
What’s the difference between a process group and a session group?
A process group is a set of processes with the same PGID (process group ID). Having the same PGID allows them to be signaled at the same time.
A session group is a set of process groups that belong to a single user’s session. There could be more than one process group in a session group.
What is the output of Dijkstra’s Algorithm (the Banker’s Algorithm)?
What’s a downside of this algorithm?
This algorithm produces a “safe state execution sequence,” i.e. an ordering in which we can run a set of processes that’s guaranteed to be deadlock-free.
It requires advanced knowledge of the memory needs for each process, and this isn’t always possible.
Name the four techniques for addressing deadlocks.
1) Live with the problem
2) Prevention
- static analysis on source code to perform an exhaustive search of possible states (doesn’t scale well beyond small programs)
- ad hoc genius (ex: the different ways we can come up with to address the Dining Philosopher’s problem)
- removing preconditions of deadlocks
3) Detection
- use graph theory to systematically detect deadlocks in a program, and then take steps to recover from them
4) Avoidance (ex. Banker’s Algorithm: use an execution sequence that will not let deadlocks happen)
Semaphores:
A) what does the p() call do?
B) what does the v() call do?
A) count –, or block
- you could think of this as “grabbing the bathroom key to get in”… and you grab it when you have to go “p” :)
- p() is the same call as semwait()
B) count ++, and wake up next process (if any) in blocked queue
- think of this as putting the key back so someone else can take it
- v() is the same call as sempost()
Note: p() and v() are both system calls. They ask the OS to do something.
Why can busy waiting lead to starvation?
There could be a situation in which the lower priority process grabs the lock, but doesn’t get to run because it’s lower priority. Meanwhile the higher priority process gets chosen to run, and it uses its quantum time to keep trying/failing to grab the lock (held by the lower priority process).
(This is the busy-waiting part, where the higher priority process keeps checking to see if it can grab the lock. The lower priority process is starving, awaiting its turn, while it does that.)
Eventually the lower priority process will get a turn, finish its work in the critical section, and release the lock, and then the higher priority process can use it. But in the meantime, time/resources wasted.
An alternative would be to have a process block if it can’t grab the lock. Then the process holding it can get right to work, and wake up the blocked process when it’s done.
What are two dangers of using semaphores?
1) programmer burden:
- could forget to call v() or p()
- could accidentally switch the order of the p() and v() calls; if v() gets called before p(), both threads will enter the critical section
2) deadlock:
- threads can become blocked in cyclical dependency
Dining Philosophers Problem: What 3 properties should a good solution have?
sound, deadlock-free, starvation-free
Dining Philosophers Problem:
If every philosopher grabs chopstick i and then chopstick i+1, what happens?
Deadlock. Every philosopher will block when they try to grab i+1, because the philosopher to their right already grabbed it when grabbing chopstick i.
Dining Philosophers Problem:
A) Describe the “global semaphore” solution.
B) What’s a downside of this solution?
A) Rather than a semaphore for each resource, there is a single global semaphore. A philosopher can only pick up chopsticks (resources) if holding the global semaphore.
B) This limits concurrency, as it just becomes a one-at-a-time queue to get the global semaphore and access the wanted resources. Ideally we’d find a solution that lets some threads run concurrently.
Dining Philosophers Problem:
A) Describe the “breaking symmetry” solution (in which the philosophers don’t all do the same thing).
B) Using this solution, how many philosophers can eat at one time?
A) Even-numbered philosophers grab chopstick i then chopstick (i+1 % N). Odd-numbered philosophers follow reverse order.
B) half of them
Dining Philosophers Problem:
A) Describe the “wait and retry” solution.
B) Downside of this solution?
A) Each philosopher picks up chopstick i and then tries to pick up chopstick i+1. If the philosopher can’t pick up the second one, drops the first, waits a bit, and then tries the whole process again.
B) This works, but it’s inefficient. Could involve wasted work of repeated effort to pick up the chopsticks until finally successful.
What is the difference between a zombie child and an orphan child?
zombie: child completed but is still in OS process table because the parent hasn’t called wait(); can be cleared by reboot
orphan: child is running but parent has terminated, so orphan will be reclaimed by init process
What are the 4 preconditions for deadlock?
1) mutual exclusion
2) no resource preemption (a process that locks a resource gets to own it until it explicitly releases it, i.e. another process can’t take it away)
3) hold and wait (process can hold resources and block if new resources can’t be acquired right away)
4) circular waiting (cyclical dependency with 2 or more processes blocked waiting for resource held by other process)
Note: You can prevent deadlock by removing any one of these preconditions. All 4 must be present for deadlock to occur.
solutions to deadlock: living with the problem
A) Given this solution, what does one do if deadlock occurs?
B) Downside of this approach?
A) Kill all processes involved and restart
B) Undesirable side effects, tricky to roll back operations in OS and databases
Deadlock prevention via removing “mutual exclusion”:
A) Why would removing mutual exclusion prevent deadlock?
B) Drawback of this solution?
A) If multiple threads can access the resource at the same time, processes can’t become stuck waiting for the resource to be released.
B) Some resources are intrinsically unsharable, so not always a desirable/possible solution.
Deadlock prevention via removing “hold and wait”:
A) How would this work, and why would it prevent deadlock?
B) Drawback of this solution?
A) Could require process to request all resources it needs up front, so it will only run when they’re all available, and it will never end up blocked while holding some of them and waiting for others.
B) It’s not always possible to know all needed resources up front.
Deadlock prevention via removing “circular waiting”:
A) How would this work, and why would it prevent deadlock?
B) Drawback of this solution?
A) Enforce order of resources, i.e. number them and only let process take resources in order of increasing number. This makes a circle impossible, preventing a cyclical dependency.
B) This requires knowing all needed resources up front (not always possible) and assigning them a suitable ordering.
Deadlock prevention via removing “no resource preemption”:
A) How would this work, and why would it prevent deadlock?
B) Drawback of this solution?
A) Allow resource preemption, i.e. allow a process to take a resource from a process that hasn’t released it yet. Could be a priority scheme: allow higher-priority process to steal resource from lower-priority process.
B) Tricky to roll back execution of lower-priority process. Also, the lower-priority process could starve.
A) What is a sound program?
B) Is it always deadlock-free?
A) A program guaranteed to produce correct results at all stages without race conditions and synchronization issues.
B) No, a program can be sound but have deadlock or starvation potential. Mutual exclusion helps with soundness but can cause these problems sometimes.
Dijkstra’s algorithm identifies certain execution states as “unsafe.”
A) Does an unsafe state always result in a deadlock?
B) Why?
A) No, deadlock situations are a subset of unsafe states, i.e. some unsafe states won’t result in a deadlock.
B) States are deemed safe or unsafe based on the max number of resources each process could request, but a process may not always request its max number of resources. Thus the notion of “safe” is conservative.
A) In Dijkstra’s algorithm, when is a request for resources valid?
B) If the request is valid, is it also safe?
A) When the number of resources requested by a process does not exceed the available number of resources, AND it would not push the number of currently held resources beyond the maximum claim for a process.
B) No, the resulting state could be unsafe even if the request is considered valid. Whether a request is safe depends on whether there exists a safe (deadlock-free) sequential ordering of all processes’ requests.
When we talk about deadlock avoidance in Dijkstra’s algorithm, we refer to the “number of resources” that each process requests. How are these resources different from the resources in the Dining Philosopher’s problem?
Dijkstra’s algorithm refers to multiple, interchangeable instances of resources, such as spaces in memory. Here only the number of resources is important.
In the Dining Philosopher’s problem, each resource is unique, such as a specific file that a process may want to access.