Bird
Raised Fist0
Interview Prepoperating-systemseasyAmazonGoogleMicrosoftFlipkartRazorpay

System Call - Mechanism & Modes (User vs Kernel)

Choose your preparation mode3 modes available
▶
Steps
setup

User Process Starts Execution

The user process is created and starts executing in user mode. It is ready to run and waiting for CPU allocation.

💡 Initialization of the user process is essential to see how system calls originate from user mode.
Line:process = create_process('UserProcess', mode='user')
💡 User processes begin in user mode and must request kernel services via system calls.
📊
System Call - Mechanism & Modes (User vs Kernel) - Watch the Algorithm Execute, Step by Step
Watching this step-by-step helps you understand the critical mode switches and the mechanism behind system calls, which are fundamental to OS security and functionality.
Step 1/10
·Active fill★Answer cell
1
ready
0
new
Ready Queue
1
Waiting Queue
empty
🖥CPUidlet=0
Transition ready → running pid:1 - scheduler dispatch
1
running
0
new
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=1
1
1
running
0
ready
Ready Queue
0
Waiting Queue
empty
🖥CPU1t=2
1
Transition ready → running pid:0 - mode switch to kernel
1
waiting
0
running
Ready Queue
empty
Waiting Queue
1 (system_call_completion)
🖥CPU0t=3
1
0
1
waiting
0
running
Ready Queue
empty
Waiting Queue
1 (system_call_completion)
🖥CPU0t=4
1
0
1
waiting
0
running
Ready Queue
empty
Waiting Queue
1 (system_call_completion)
🖥CPU0t=5
1
0
Transition running → waiting pid:0 - system call complete
1
ready
0
waiting
Ready Queue
1
Waiting Queue
empty
🖥CPUidlet=6
1
0
Transition ready → running pid:1 - scheduler dispatch
1
running
0
waiting
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=7
1
0
1
1
running
0
waiting
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=8
1
0
1
1
running
0
waiting
Ready Queue
empty
Waiting Queue
empty
🖥CPU1t=9
1
0
1

Key Takeaways

✓ System calls cause a controlled switch from user mode to kernel mode to safely execute privileged operations.

This mode switch is hard to grasp from code alone because it involves CPU privilege levels and hardware interrupts.

✓ The kernel validates system call parameters to maintain system security and stability.

Seeing this validation step visually clarifies the kernel's protective role during system calls.

✓ After kernel handling, control returns to the user process transparently, allowing seamless continuation of user code.

Understanding the full cycle of request, kernel handling, and return is easier when watching the process states and mode switches.

Practice

(1/5)
1. In which scenario is Peterson's solution most appropriate for managing access to a critical section?
easy
A. When exactly two processes need mutual exclusion without relying on hardware atomic instructions
B. When processes require synchronization but can tolerate starvation
C. When multiple processes (more than two) need to synchronize access to a shared resource
D. When the system supports preemptive multitasking with priority-based scheduling

Solution

  1. Step 1: Identify Peterson's solution scope

    Peterson's algorithm is designed specifically for two processes to achieve mutual exclusion without hardware support.
  2. Step 2: Analyze other options

    When multiple processes (more than two) need to synchronize access to a shared resource is incorrect because Peterson's solution does not scale beyond two processes. When processes require synchronization but can tolerate starvation is wrong because Peterson's solution guarantees bounded waiting, preventing starvation. When the system supports preemptive multitasking with priority-based scheduling is irrelevant since Peterson's algorithm is independent of scheduling policies.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Peterson's solution is a classic two-process synchronization algorithm without hardware atomic instructions.
Hint: Peterson's solution = two-process mutual exclusion without hardware locks
Common Mistakes:
  • Assuming Peterson's works for more than two processes
  • Confusing bounded waiting with starvation allowance
  • Believing hardware support is required
2. In which scenario is the SSTF (Shortest Seek Time First) disk scheduling algorithm most appropriate compared to SCAN or C-SCAN?
easy
A. When minimizing average seek time is the highest priority and starvation is acceptable
B. When fairness and avoiding starvation are more important than minimizing seek time
C. When the disk requests are uniformly distributed and the workload is heavy
D. When the disk head movement must always proceed in one direction only

Solution

  1. Step 1: Understand SSTF's goal

    SSTF selects the closest request to the current head position to minimize seek time.
  2. Step 2: Consider starvation risk

    SSTF can cause starvation for requests far from the current head position because it always picks the nearest request.
  3. Step 3: Compare with SCAN and C-SCAN

    SCAN and C-SCAN move the head in a fixed direction to provide fairness and avoid starvation, sacrificing some seek time efficiency.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    When minimizing average seek time is the highest priority and starvation is acceptable correctly identifies SSTF's strength and its tradeoff with starvation risk.
Hint: SSTF = fastest seek but can starve distant requests
Common Mistakes:
  • Assuming SSTF always avoids starvation
  • Believing SCAN/C-SCAN minimize seek time better than SSTF
  • Confusing uniform distribution with SSTF suitability
3. Trace the sequence of events when a process exceeds its working set size causing thrashing. What happens step-by-step inside the system?
easy
A. The process generates page faults, the OS increases its frame allocation, and thrashing stops immediately
B. The process generates page faults, the OS swaps out pages not in the working set, but thrashing continues due to insufficient frames
C. The process generates page faults, the OS ignores them, and the process continues without delay
D. The process generates page faults, the OS reduces the number of processes to free frames, preventing thrashing

Solution

  1. Step 1: Identify what happens when working set is exceeded

    The process causes frequent page faults because its active pages exceed allocated frames.
  2. Step 2: OS response

    The OS attempts to swap out pages not in the working set to free frames, but if frames are insufficient, thrashing persists.
  3. Step 3: Analyze options

    A is incorrect because OS cannot always increase frames immediately; thrashing may continue.
    B is correct as it describes the OS swapping out pages but thrashing continuing due to frame shortage.
    C is incorrect because OS does not ignore page faults.
    D is incorrect because load control (reducing processes) is a prevention technique but not an immediate response to page faults.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Thrashing occurs when working set exceeds frames; OS tries to swap but may fail if frames are insufficient.
Hint: Thrashing = page faults + insufficient frames despite swapping
Common Mistakes:
  • Assuming OS can instantly allocate more frames
  • Believing OS ignores page faults
  • Confusing immediate load control with page fault handling
4. Which of the following is a major trade-off when using indexed file allocation compared to contiguous allocation?
medium
A. Indexed allocation requires additional disk space for index blocks, increasing overhead
B. Indexed allocation causes more external fragmentation than contiguous allocation
C. Indexed allocation cannot support direct access to file blocks
D. Indexed allocation always results in slower sequential access than linked allocation

Solution

  1. Step 1: Understand indexed allocation overhead

    Indexed allocation stores pointers in index blocks, consuming extra disk space.
  2. Step 2: Analyze indexed allocation requires additional disk space for index blocks, increasing overhead

    Correctly identifies the overhead cost of index blocks.
  3. Step 3: Analyze indexed allocation causes more external fragmentation than contiguous allocation

    Indexed allocation reduces external fragmentation by allowing non-contiguous blocks.
  4. Step 4: Analyze indexed allocation cannot support direct access to file blocks

    Indexed allocation supports direct access via the index block.
  5. Step 5: Analyze indexed allocation always results in slower sequential access than linked allocation

    Sequential access speed is generally better than linked allocation due to direct indexing.
  6. Final Answer:

    Option A -> Option A
  7. Quick Check:

    Indexed allocation trades space overhead for flexible block placement and direct access.
Hint: Indexed allocation trades space overhead for direct access [OK]
Common Mistakes:
  • Confusing external fragmentation effects between allocation methods
  • Believing indexed allocation cannot do direct access
  • Assuming indexed allocation is always slower than linked for sequential access
5. If a system uses LRU page replacement but the reference string exhibits a cyclic pattern larger than the number of frames, what is the expected impact on page faults compared to FIFO?
hard
A. LRU will have fewer page faults because it always evicts the least recently used page
B. LRU will perform optimally and minimize page faults in cyclic patterns
C. LRU will have more page faults than FIFO because it keeps evicting pages that will be needed soon
D. LRU and FIFO will have similar page fault rates due to cyclic references exceeding frame count

Solution

  1. Step 1: Understand cyclic reference pattern larger than frames

    Pages are referenced in a cycle longer than available frames, causing repeated evictions.
  2. Step 2: Analyze LRU vs FIFO behavior

    Both algorithms will evict pages that will be needed soon because the working set exceeds frame count.
    LRU's advantage diminishes as no page stays long enough to be reused before eviction.
  3. Step 3: Evaluate options

    LRU will have fewer page faults because it always evicts the least recently used page is false; LRU advantage is lost in cyclic patterns larger than frames.
    LRU will perform optimally and minimize page faults in cyclic patterns is false; both have similar fault rates in this scenario.
    LRU will have more page faults than FIFO because it keeps evicting pages that will be needed soon is false; LRU does not necessarily have more faults than FIFO here.
    LRU and FIFO will have similar page fault rates due to cyclic references exceeding frame count is true; LRU and FIFO have similar fault rates due to cyclic references exceeding frame count.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    When working set > frames, LRU and FIFO fault rates converge.
Hint: LRU loses advantage when working set exceeds frames [OK]
Common Mistakes:
  • Assuming LRU always outperforms FIFO
  • Believing cyclic patterns favor LRU
  • Thinking LRU is optimal in all cases
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard