Midterm Exam Flashcards Preview

Operating Systems > Midterm Exam > Flashcards

Flashcards in Midterm Exam Deck (76):
1

What is an OS?

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

2

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.

3

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.

4

What is a CPU?

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

5

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.

6

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

7

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

Registers
Caches
MM
Disk
Cloud

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

8

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

CPU ? Registers ? MM ? Hard Disk > Cloud

9

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

a. Milliseconds
b. Seconds
c. Nanoseconds

1c, 2a, 3b

10

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.

11

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

12

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.

13

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.

14

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.

15

Multiprogrammed Computer

Multiple jobs executing at the same time.

16

Multiprocessor System

Multiple CPUs

17

What happens when an I/O call is COMPLETED?

Device sets an interrupt in the interrupt register.

18

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

True, every bit has its own respective priority.

19

What is a trap?

A software interrupt.

20

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

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

21

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.

22

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.

23

How does the CPU prevent infinite loops from destroying resources?

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

24

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.

25

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

26

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

27

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.

28

What five things make up a process?

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

29

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
Accounting
Register Values- Context of a process
Pid of Parent
State of process

30

Process Life Cycle

[Look up in notes]

31

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

32

What is the init program?

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

33

True/False: Every process created has a parent.

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

34

What are the three system calls for process creation?

fork()
exec()
wait()

35

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

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

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

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

fork()

37

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

True

38

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.

39

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.

40

What happens when a process terminates?

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

41

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.

42

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.

43

Draw the process tree.

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

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

44

Draw the process tree.

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

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

45

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

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

46

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.

47

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.

48

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.

49

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

True

50

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.

51

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

There is virtually no difference from an OS perspective.

52

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

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

53

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.

54

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

55

What is the equation for response time?

RT = Wait time + Service time

56

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

True

57

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

Ensure that a job does not wait endlessly.

58

FIFO(FCFS)

- 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

LCFS(Preemptive)

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

SJF(Non-preemptive)

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

SJF(Preemptive)

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

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.

63

MLF(Non-preemptive)

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

64

MLF(Preemptive)

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

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

66

What is mutual exclusion?

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

67

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.

68

What are the three main solutions critical section implementation?

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

69

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)

70

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.

71

What is the widely recognized software solution to the implementation?

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

72

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.

73

What are two main hardware solutions to the implementation?

1. Disable interrupts.
2. Atomic HW functions

74

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

Extends to N threads.

75

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

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

76

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

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