Midterm Exam Flashcards

1
Q

What is an OS?

A
  • SIts right on top of hardware

- User interface to computers hardware

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A
  • Complex
  • In the background
  • It controls EVERYTHING: HW, your program, all the SW and HW devices connected to your computer, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a kernel?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a CPU?

A
  • Core of computer
  • Runs all instructions
  • Very fast (Usually multiple GHz: GHz = 10^9 instructions per second)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the bottleneck of a typical computer system?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the four main responsibilities of the OS?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A
Registers
Caches
MM
Disk
Cloud

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List the following items from highest speed to lowest speed:

CPU, MM, Registers, Hard Disk, Cloud

A

CPU ? Registers ? MM ? Hard Disk > Cloud

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Match the level of speed between the following items:

  1. CPU
  2. Disk
  3. User

a. Milliseconds
b. Seconds
c. Nanoseconds

A

1c, 2a, 3b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is caching?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A
  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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens when an I/O call is REACHED?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe in detail how a CPU “talks” to a mechanical device.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Multiprogrammed Computer

A

Multiple jobs executing at the same time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Multiprocessor System

A

Multiple CPUs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens when an I/O call is COMPLETED?

A

Device sets an interrupt in the interrupt register.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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

A

True, every bit has its own respective priority.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a trap?

A

A software interrupt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How does the CPU prevent infinite loops from destroying resources?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

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

A

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

Every address the program generates is checked against these registers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

When does the mode bit change to 1?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What five things make up a process?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is a PCB?

A
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
Accounting
Register Values- Context of a process
Pid of Parent
State of process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Process Life Cycle

A

[Look up in notes]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

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

A

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

32
Q

What is the init program?

A

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

33
Q

True/False: Every process created has a parent.

A

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

34
Q

What are the three system calls for process creation?

A

fork()
exec()
wait()

35
Q

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

printf(“Date\n”);
execl(“date”, “date”, NULL);
printf(“done\n”);

A

Date
[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.

36
Q

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

A

fork()

37
Q

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

A

True

38
Q

Define fork()

A

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.

39
Q

Define wait()

A

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.

40
Q

What happens when a process terminates?

A

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

41
Q

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

A

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

42
Q

What happens if parent dies but child is still running?

A

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

43
Q

Draw the process tree.

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

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

44
Q

Draw the process tree.

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

——> 2
1 —–> 3
—–> 4

45
Q

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

A

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

46
Q

What is the fundamental design principle when programming with threads?

A

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.

47
Q

How do threads get time on the CPU?

A

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.

48
Q

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

A

False, they can be mapped to kernel threads.

1:1 mapping, 1:N mapping, M:N mapping.

49
Q

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

A

True

50
Q

What are three main advantages of threads over processes?

A
  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.
51
Q

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

A

There is virtually no difference from an OS perspective.

52
Q
What will this code do?
main(){
  signal(SIGINT, alter);
}
void alter(){
  printf("Nope.\n"");
}
A

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

53
Q

What are the two main types of schedulers?

A

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.

54
Q

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

A
  1. Response time (From user’s perspective)
  2. Throughput (From management’s perspective)
  3. Fairness
55
Q

What is the equation for response time?

A

RT = Wait time + Service time

56
Q

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

A

True

57
Q

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

A

Ensure that a job does not wait endlessly.

58
Q

FIFO(FCFS)

A
  • 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.
59
Q

LCFS(Preemptive)

A

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

60
Q

SJF(Non-preemptive)

A

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.

61
Q

SJF(Preemptive)

A

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.

62
Q

Round Robin

A

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.

63
Q

MLF(Non-preemptive)

A

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

64
Q

MLF(Preemptive)

A

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.

65
Q

Four approaches to evaluate a scheduling policy.

A
  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
66
Q

What is mutual exclusion?

A

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

67
Q

What is a race condition?

A

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

68
Q

What are the three main solutions critical section implementation?

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

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

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

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

A
  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.
71
Q

What is the widely recognized software solution to the implementation?

A

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

72
Q

What are three disadvantages of the SW solution?

A
  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.
73
Q

What are two main hardware solutions to the implementation?

A
  1. Disable interrupts.

2. Atomic HW functions

74
Q

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

A

Extends to N threads.

75
Q

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

A
  1. Spin locking.

2. Starvation is still possible.

76
Q

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

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