Midterm Exam Flashcards Preview

Operating Systems > Midterm Exam > Flashcards

Flashcards in Midterm Exam Deck (76):

What is an OS?

- SIts right on top of hardware
- User interface to computers hardware


What are three main differences between the OS and your program?

- Complex
- In the background
- It controls EVERYTHING: HW, your program, all the SW and HW devices connected to your computer, etc.


What is a kernel?

Commonly referred to as another name for the OS. It is an essential part of the OS that is always running. It is always in main memory, and is loaded when the computer is switched on and stays running until shut down.


What is a CPU?

- Core of computer
- Runs all instructions
- Very fast (Usually multiple GHz: GHz = 10^9 instructions per second)


What is the bottleneck of a typical computer system?

Bottleneck: The slowest part of a system, a process runs only as fast as the bottleneck will allow.

Answer: Main memory, not nearly as fast as the other components in the system.


What are the four main responsibilities of the OS?

1) Process Management: How the CPU executes your code
2) Memory Management: Mapping from logical to physical addresses; how your code is stored in MM.
3) File Systems: How your files are stored on hard disk.
4) Storage Management: Disk scheduling policies


Describe the storage hierarchy. Include the effect of speed, cost, and space.


As you move up:
Cost increases, speed increases.
As you move down:
Space increases


List the following items from highest speed to lowest speed:
CPU, MM, Registers, Hard Disk, Cloud

CPU ? Registers ? MM ? Hard Disk > Cloud


Match the level of speed between the following items:
1. CPU
2. Disk
3. User

a. Milliseconds
b. Seconds
c. Nanoseconds

1c, 2a, 3b


What is caching?

Part of the OS that decides what data to load higher up the storage hierarchy and what data to eject lower down the storage hierarchy.


What are the three main tasks in the fetch execute cycle?

1. Check interrupt register.
2. If set, call OS and set PC to handle interrupt. If not set, check PC.
3. Fetch next instruction
4. Execute instruction


Why is I/O an issue in regards to CPU processing time?

CPU cannot sit idle when I/O function is reached for two reasons.
1) I/O is very slow
2) Your program has no control outside its memory area.


What happens when an I/O call is REACHED?

Program stops (loses control of CPU). OS takes over and checks permissions. After, the CPU tells I/O device to perform job and then switches to another program.


Describe in detail how a CPU "talks" to a mechanical device.

CPU issues commands through driver to talk to the controller which controls a mechanical device.

Driver: Piece of software that allows CPU to communicate with controller (every controller has its own commands, or 'language').

Controller: Piece of hardware that communicates directly with the device.


Multiprogrammed Computer

Multiple jobs executing at the same time.


Multiprocessor System

Multiple CPUs


What happens when an I/O call is COMPLETED?

Device sets an interrupt in the interrupt register.


True/False: Some bits in the interrupt register are more important than others.

True, every bit has its own respective priority.


What is a trap?

A software interrupt.


True/False: Some controllers do not have a bit in the interrupt register.

False, every controller MUST have a bit in the interrupt register.


Why would any system want to use program controlled I/O?

While it does waste the utilization of the CPU, it has an important practicality when realtime systems are involved. This is because the response time for these types of systems is critical.


Does the CPU have a higher priority than the DMA controller? Why or why not?

No because the DMA runs much more infrequently compared to the CPU. The DMA would starve if it did not have more priority.


How does the CPU prevent infinite loops from destroying resources?

Has a timeout for running programs (interrupt is set on expiration).


How does the OS ensure that your program does not read/write another programs memory over?

Two registers:
MBR- Memory base register
MLR- Memory limit register

Every address the program generates is checked against these registers.


How does the CPU know that it is executing the OS vs. your program?

The mode bit:
1 when OS runs(kernel mode, OS mode, supervisor mode)
0 when your code runs


What are the steps taken when a computer is turned on?

1) HW/ROM(read-only memory) initialization
2) Loads OS into MM and sets mode bit to 1
3) OS runs, SW initialization occurs
4) Login Prompt
5) When user logs in, OS checks authentication of user
6) OS (normally) sets mode bit to 0 and gives control to user


When does the mode bit change to 1?

The CPU checks interrupt register. If an interrupt has been set, then the CPU sets the mode bit to 1 and gives control to the OS.


What five things make up a process?

Its text, variables, stack, heap, and set of resources used by the program.


What is a PCB?

Program Control Block, Data structure used to keep track of processes. It also keeps track of:
Process id #
Where the program is loaded in MM
Files opened by the program
Owner of the Process
CPU scheduling information
I/O status
Register Values- Context of a process
Pid of Parent
State of process


Process Life Cycle

[Look up in notes]


What are the five main data structures needed by the OS to keep track of processes?

1) PCB for each process
2) CPU queue
3) Disk queue
4) MM queue
5) Process Table


What is the init program?

The FIRST program of the OS that runs- PID # 1


True/False: Every process created has a parent.

True, every process leads back to the init program up the process tree.


What are the three system calls for process creation?



What is the output of the following program? Explain why.

execl("date", "date", NULL);

[Whatever today's date/time is]

Done is NOT printed. This is because exec wipes out the programs address space with date. The PID remains unchanged, and it cannot return to the calling program since the address space of the calling program was erased.


Out of the three main system calls for process creation, which is the most expensive in terms of resources?



True/False: Parents can kill children, but children cannot kill parents.



Define fork()

Creates a new child process that is identical to the parent.
Child has a new PID#
Child entry inserted into process table and CPU queue
Child's process ID from the standpoint of the calling program is 0.


Define wait()

Waits for the child process to complete before continuing execution. Returns immediately if the calling process has no children or if the children have been terminated.


What happens when a process terminates?

The OS closes all open files, releases all memory, and it is removed from the OS data structures.


What if the parent is alive but has not called wait?

The child becomes a zombie. The OS erases memory address space but retains the process table entry of a child.


What happens if parent dies but child is still running?

The child becomes an orphan and gets adopted by the init process. Init will call wait.


Draw the process tree.

for(int i = 1; i < 4; i++){
cid = fork();
if(cid > 0)

1 ----> 2 ----> 3 ----> 4


Draw the process tree.

for(int i = 1; i < 4; i++){
cid = fork();
if(cid = 0)

------> 2
1 -----> 3
-----> 4


What are the six main items that a thread shares with its parent program?

Text, open files, global variables, children, pending alarms, stack.


What is the fundamental design principle when programming with threads?

When you have independent jobs (memory management, cpu scheduling, files, etc.) create child processes, one for each job.

When programming one main task, create threads to handle different parts of that main task.


How do threads get time on the CPU?

It depends on the type of thread.

User: shares with parent, OS is not aware of its existence

Kernel: Get their own time on the CPU separate from parent, OS is aware of their existence. Each thread can be assigned to a different CPU in a multiprocessor system.


True/False: It is not possible for user threads to get their own time on the CPU.

False, they can be mapped to kernel threads.
1:1 mapping, 1:N mapping, M:N mapping.


True/False: A thread can read/write or even completely wipe out another sibling thread because there is no protection between threads.



What are three main advantages of threads over processes?

1. Threads share address space, very useful for many applications.
2. Easier to create and kill threads than child processes since threads have no resources attached to them.
3. Multiprocessor systems makes thread programming very efficient.


Define the difference between signals, traps, and interrupts from an OS perspective.

There is virtually no difference from an OS perspective.


What will this code do?
signal(SIGINT, alter);
void alter(){

Whenever a user tries to enter CTRL c, it will instead print "Nope." to the screen.


What are the two main types of schedulers?

CPU Scheduler: Determines which job gets the CPU next.

MM Scheduler: Tries to ensure that there are a mix of I/O bound jobs (short) and CPU Bound Jobs (long) in memory.


What are the three factors used to evaluate an OS algorithm?

1. Response time (From user's perspective)
2. Throughput (From management's perspective)
3. Fairness


What is the equation for response time?

RT = Wait time + Service time


True/False: OS jobs get higher priority than user jobs.



The OS tries to ensure that jobs are "Starvation Free". Define that term.

Ensure that a job does not wait endlessly.



- Non-preemptive policy.
- Once you get the CPU, you have the highest priority, and you continue until you exit or block for I/O.
- Biased towards long jobs.



A new job starts executing immediately when it comes in. The last job that was on the queue has priority if it is preempted.



When a new job comes in, it goes to head of the queue if it has a shorter time remaining than the current remaining job. It does NOT take the CPU away from the job that is running.



When a new job comes in, if it has a shorter remaining time than the job currently running, it preempts it and takes over the CPU. If the job running has an equal time remaining to the job coming in, the job remaining keeps executing. Best policy in terms of RT and throughput, but predicting job length is a potential challenge. It is also an unfair policy.


Round Robin

There is a time quantum. A job runs as long as its time quantum will allow and then concedes the CPU to the head of the queue. Very fair policy.



There is quantum time associated with each QUEUE. An incoming process will not interrupt another process before its quantum time is over.



There is quantum time associated with each QUEUE. An incoming process WILL interrupt another process before its quantum time is over if it has a higher priority.


Four approaches to evaluate a scheduling policy.

1. Deterministic: Fixed example
2. Implementation: actually implement the policy
3. Simulation: Write programs to simulate the system
4. Analytic: What the boxes are doing


What is mutual exclusion?

Two threads cannot access the critical section at the same time.


What is a race condition?

The outcome of the program depends on the order in which execution takes place. Want to ensure that a race condition does NOT occur.


What are the three main solutions critical section implementation?

1. Software: No HW or OS support.
2. Hardware (atomic functions)
3. OS


What are the three ways to implementation using the OPERATING SYSTEM?

1. Mutexes(key/unlock): Binary sempahore
2. Semaphores(multiple threads allowed in critical section)
3. Monitors(conditions)


What are the six main properties that you want from a critical section solution?

1. Mutual Exclusion should hold: only one thread in .
2. Starvation Free: A thread should get its turn entering the
3. Deadlock Free: No threads are able to get into the
4. termination: a thread remains in the for a finite time, no while loops.
5. Legal death: A thread terminating outside of the code (inside the remainder code) should not block other threads from entering the .
6. No speed differential: If are thread wants to enter the more often, it should be allowed to do so.


What is the widely recognized software solution to the implementation?

The peterson solution, uses two permission variables and a turn variable.


What are three disadvantages of the SW solution?

1. A blocked thread uses CPU while waiting for . BUSY WAITING or SPIN LOCKING.
2. Difficult to extend solution to n threads.
3. Difficult to prove code correctness.


What are two main hardware solutions to the implementation?

1. Disable interrupts.
2. Atomic HW functions


What is one main advantage of the hardware solution to the implementation?

Extends to N threads.


What are two main advantages of the hardware solution to the implementation?

1. Spin locking.
2. Starvation is still possible.


What are the ONLY three operations that can be done to a semaphore?

1. It can be initialized.
2. p()
3. v()