CPU Virtualizing: Processes & Scheduling Flashcards

1
Q

What happens when you run a program?

A

Loads from disk to memory
The CPU, using its instruction Set Architecture (ISA), sequentially:
Fetches an instruction from memory.
Decodes to identify the specific command.
Executes the identified operation(e.g, adding numbers, memory access, function jumps.)
Move to next instruction
The cycle repeats billions of times every second until the program finishes
Despite this simple model, many other complex processes occur during a program’s execution.

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

Explain short: What is the goal of process abstraction?

A

The goal of process abstraction is to run multiple processes concurrently, by time sharing the cpu. We then need mechanisms (context switch) and policy(scheduler). This makes the illuision that each program has it’s own isolated machine.

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

What is virtualization of the CPU?

A

It involves a single cpu acting as if it were multiple seperate CPUs- Enables users to run many concurrent programs

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

Which states can a process be? Explain them.

A

Running: The process is actively executing instruction on a processor.

Ready: The process is prepared to run but isn’t currently chosen by the OS to execute.

Blocked: The process is waiting for an event before it can proceed. For instance, a process become blocked when initiating an I/O request to a disk or network, allowing another process to use the processor in the meantime

Running to Ready: The OS interrupts the running process and puts it back in the queue to wait its turn.
Running to Blocked: The process initiates I/O, like reading from a disk, and can't run until the I/O is done.
Ready to Running: The OS decides it's this process's turn to run.
Blocked to Ready: The I/O operation that was blocking the process is now finished.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does fork() do? What does exec() do What does wait() do?

A

The fork() function creates a new process, which is an exact copy of the calling process. It’s like having two identical versions of the original process, both seemingly continuing from where fork() was called

The wait() system call allows the parent process to pause and wait until its child process finishes. Once the child completes, the parents resume, and wait() provides the child’s PID as its return value. This will always make the child go first.

Exec()
Loads the code and static data from the file.
Overwrites current code segment and static data of the process.
Re-initializes the heap and stack to match the new program’s requirements.

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

What different modes can an OS run an executable from?

A

User and kernel mode

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

What is kernel mode?

A

In Kernel mode:

The OS can run system calls.
The OS doesn't trust the user's stack or provided addresses.
The OS has full access to the hardware, like using any CPU instruction and accessing any memory.
Kernel mode is for the most trusted and low-level OS functions.
Crashes in kernel mode can stop the whole computer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the two types of scheduler?

A

Preemptive and non preemptive

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

What is a context switch?

A

For example when a process switches from user to kernel mode. It then saves context (PC, registers, kernel stack, pointer) of process on kernel stack

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

What is SJF (shortest-job-first)?

A

It runs the shortest job available, not preemptive

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

What is FIFO (first-in first-out)?

A

It runs the process with the shortest arrival time

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

What is RR (round-robin), and how does it work?

A

A scheduling algorithm.| It runs each process on a given time quatum. This could be 2ms.

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

Why do we want to have a scheduler?

A

Maximize CPU usage.
Minimize turnaround time (arrival to completion).
Minimize response time (arrival to first scheduling).
Ensure fairness for all processes.
Minimize overhead by running processes long enough to cover context switch costs (e.g., 1 microsecond).

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

What is stride scheduling?

A

Each process is assigned a ticket value.
We calculate a “stride” for each process using a fixed number (e.g., 1000 or 10000).
A “pass” value is increased by the stride value for each process.
The operating system selects the process with the lowest pass value to run.
If multiple processes have the same pass value, the one with the lowest stride value runs first.
If both pass and stride values are identical, the process that entered the scheduling queue first gets to run first.

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

What is the formula for turnaround time? What is turnaround time?

A

Tturnaround = Tcompletion - Tarrival

Scheduler performance is measured using turnaround time, which is the duration from a process entering the queue to its completion. Interestingly, better turnaround times can sometimes mean less fairness in scheduling.

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

What is the formula for response time?

A

Tresponse = Tfirstrun - Tarrival

17
Q

Why is it difficult to create a good scheduler?

A

Turnaround time and response time:| Both are bad where the other is good

18
Q

What is multi-level feedback queue(MLFQ)?

A

The scheduler has different priority levels for processes, and it uses a round-robin approach within each priority level. It starts with the highest-priority process and moves down if not done. If two processes have the same priority, they take turns in a round-robin fashion.

19
Q

What are some of the problems with multi-level feedback queue(MLFQ)?

A

Starvation: If there are to many interactive jobs they will combine to consume a lot cpu time, preventing long running jobs from getting any cpu time, so they starve.

20
Q

What can we done in MLFQ to prevent starvation?

A

Periodically boost the priority level of all jobs. For a given time slice we can move all jobs to the highest priority queue.

21
Q

What is lottery scheduling?

A

Each process gets different amount of tickets and an OS chooses a ticket. The process that has that ticket can run for a given time.

22
Q

How do we calculate fairness in a scheduler?

A

U = tCompletionA / tCompletionB (1 = perfect)

23
Q

What is the difference between lottery scheduler and stride scheduler?

A

Stride scheduler is deterministic

24
Q

What are the advantages and disadvantages of using randomness in a scheduler?

A

Negative:

Unpredictable: Lottery scheduling can't guarantee exact proportions, leading to uncertain outcomes.

Positive:

Fairness: It promotes fairness.
Lightweight for the OS.
Avoids corner cases.
25
Q

How does the OS schedule threads?

A

OS schedules threads that are ready to run independently, much like processes

26
Q

When and what , trap function

A

A trap function, also known as a system call:

Used by a program when it requires privileged access or services provided by the operating system.
Necessary when the program intends to perform tasks like file operations, I/O, process control, and more.
Specifies the specific action or service the program is requesting from the operating system.
    For instance, opening a file, allocating memory, creating a new process, or executing network operations.
Essentially allows a program to seek the operating system's assistance for tasks beyond its direct capabilities.
Encompasses both the timing of the request (when) and the nature of the requested operation (what).