cs152 quiz 2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:09 PM on 10/21/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

15 Terms

1
New cards

What is a process?

A process is a program in execution. It is an active instance of a program that is being run by the operating system. It represents the OS abstraction of execution, meaning the OS treats each running program as a separate process that it manages independently.

2
New cards

What does each process contain?

Each process contains all of the information the OS needs to manage its execution. This includes the code, data, heap, and stack memory along with the CPU states (registers and PC) and process ID (PID). It also includes OS resources like open files and network connections, plus scheduling and accounting information, all stored in the process control block (PCB).

3
New cards

Define each state in an execution graph?

New: Process is about to be created.

Ready: Process is in the ready queue and is ready to be scheduled for execution.

Running: Process is currently running on CPU.

Waiting (blocked): Process is waiting for certain operations to be completed, such as I/O, page faults, or synchronization events (semaphore)

New → Ready → Running ←>Waiting  → Terminated

4
New cards

Explain what causes a transition from one state to another in an execution state graph?

New → Ready: When the process is created through the system call fork() or createProcess() and is fully setup, placed into the ready queue.

Ready → Running: When the scheduler in the OS selects a process from the ready queue to run on the CPU
Running→ Ready: When the scheduler preempts (pauses) the current process, often when time expires, higher priority process is ready, etc. Almost always during a context switch.

Running → Waiting: The running process performs an operation that requires waiting and is placed on wait queue for operation.

Waiting → Ready: Process waiting condition is satisfied, removed from wait queue added to ready queue.

Waiting → Terminated: The process finishes execution (calls exit()) and the OS releases its resources.

5
New cards

Describe what happens and why when you run sleep 3 in shell?

The shell (parent) forks a new child process that executes a sleep program. The shell then waits for the child to finish, so it is blocked for 3 seconds, and once the child terminates, the shell resumes accepting new commands. This happens because fork() creates a separate child process and the shell uses wait() to block itself.

6
New cards

Describe what happens and why when you run exec sleep 3 on shell?

The shell does not fork a new process, instead the shell process is replaced by the sleep program. After sleeping for 3 seconds, the process terminates, so shell no longer exists and the terminal closes. This occurs because exec() replaces current process memory with the new program.

7
New cards

How many hello world statements will be printed and why?

Fork() creates a new process duplicate of the calling process, so after each fork, both parent and child continue execution. After i = 0, there are 2 processes. After i = 1, the 2 processes call fork again, so there are 4 processes. 2^ 2 = 4.

8
New cards

If n = 10, how many messages will be printed and why?

2^10 = 1024. Each fork() call doubles the number of processes. After 10 iterations of the loop, there are 2^10 processes, and each executes printf() once.

9
New cards

What is preemptive scheduling?

Preemptive scheduling is when the OS interrupts a running process and moves it back to the ready queue before it finishes, allowing higher priority or time shared processes to run.

10
New cards

What is non-preemptive scheduling?

Non-preemptive scheduling is when the running process continues until it voluntarily blocks (for I/O) or finishes, and the scheduler only picks up a new process when this happens.

11
New cards

What is response time?

Response time is the time from when a job arrives in the system to the first time it starts executing on the CPU.

12
New cards

What is turnaround time?

Turnaround time is the total time from when a job arrives in the system to when it finishes execution.

13
New cards

Compare FIFO, SJF, SRTF, and RR

FIFO (First in First Out): non-preemptive, non-optimal response time, turnaround is worst for short jobs, no starvation.

SJF (Shortest Job First): non-preemptive, optimal response time for short jobs, turnaround is better for short jobs, starvation for long jobs.

SRTF (Shortest Remaining Time First): preemptive, optimal response time for short jobs, turnaround is even worse for long jobs than sjf, starvation for long jobs.

RR (Round Robin): preemptive, non-optimal but better than FIFO, turnaround is worse than SRTF, no starvation.

Preemptiveness: SRTF, RR, SJF, FIFO

Response time: SRTF, SJF, RR, FIFO

Turnaround time: SJF, SRTF, RR FIFO

Starvation: RR, FIFO, SJF, SRTF

14
New cards

How does a multi level feedback queue ensure short response times for interactive jobs?

The MLFG ensures short response times for interactive jobs because these jobs typically don’t use up their full time slice, and thus remain in the top-level queue. Jobs in the top level queue have short time slices and are scheduled first in a round robin manner, so they get CPU access quickly and frequently, keeping their response times very short.

15
New cards

How does a multi level feedback queue avoid starvation?

In a multi level feedback queue, the OS periodically boosts all jobs back to the top-levele queue to ensure that even long-running or CPU bound jobs eventually get CPU time, giving every job a fair chance to run, avoiding starvation.