Exam Theory Flashcards

1
Q

Explain the primary functions of an operating system and their importance.

A

Run user programs in robust and efficient way.
(PMSD)

  • Process management: switch between processes (CPU utilization)
  • Memory management: allocates and protects memory for processes (prevents conflicts, max performance)
  • Storage management: organizes access to storage devices (organized data, secure and efficient retrieved)
  • Device driver management: communication with hardware devices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the kernel?

A

First program loaded in memory.

Runs in kernel mode and has full hardware access.

Ensures system security, error protection, and hardware abstraction.

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

Explain what is the kernel mode of the CPU. Why is it necessary?

A

Special mode in the CPU in which the OS has full access to memory and hardware.

Provides a secure environment for the system and abstraction to work with different kinds of hardware.

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

What is a system call? How does it differ from a regular function call?

A

Set of functions that run in Kernel mode. Have more privileges than regular functions that run in user mode. They switch the CPU to run in kernel mode.

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

What is a shell? Why is it important?

A

Program that allows interaction with the OS through CLI or GUI. Important because lets user access OS services without accessing the kernel itself.

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

Differentiate between a process and a program, providing examples.

A

Program: Set of instructions in machine code. (C file)
Process: Program in execution that has a state in memory. (Executable)

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

Define multiprogramming and time-sharing systems. How do they improve system performance?

A

Multiprogramming: Runs multiple programs on single CPU by switching between them; improves CPU utilization.

Time-sharing: Extends multiprogramming giving small time slices to each process for better responsiveness.

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

What is concurrency? How can a single CPU achieve concurrency?

A

Capability of the OS to run multiple tasks at the same time. A single CPU achieves this by quickly switching between processes.

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

Compare preemptive and non-preemptive scheduling. Provide advantages and disadvantages of each.

A

Preemptive: OS pause execution at any time.

  • Pros: More responsive and fair distribution of CPU.
  • Cons: More complex, risk of overhead due to context switch.

Non-preemptive: Process runs until completion or system call.

  • Pros: Simpler, less overhead.
  • Cons: Risk of blocking processes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define the role of a CPU scheduler. How does it influence performance and responsiveness of the computer?

A

Selects the next running process. It ensures maximum CPU usage and minimum waiting times.

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

What is a time quantum in CPU scheduling? How does it affect system performance?

A

Fixed amount of time given to a process before it is paused in a preemptive system.

  • Too long: Reduces responsiveness.
  • Too short: Increases overhead due to constant context switch.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe a context switch. What steps are involved in this process?

A

Process of saving current state in memory and loading the state of the next program in execution.

Steps: Save current PCB → Move PCB to queue → Load next PCB → Resume.

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

List and explain the possible states of a process in an operating system.

A

(Never RRun Without Thinking)

  • New: Just created.
  • Ready: Waiting for CPU.
  • Running: Actively executing.
  • Waiting: Blocked, awaiting an event.
  • Terminated: Completed or killed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Process Control Block (PCB), and what information does it store?

A

Data structure that stores info related to each process.

  • State
  • PID
  • Program Counter
  • Registers
  • Memory-management info
  • Accounting information
  • I/O status
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define a logical memory address. How does it differ from a physical memory address, and what purpose does this distinction serve?

A

Logical address: Address given by the CPU during execution time. It’s not the address in memory.

Physical address: Corresponds to the actual memory address in RAM

Difference: Different processes can have the same logical address but the MMU will link them to different physical addresses.

Ensures memory protection and process isolation.

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

In the context of virtual memory, what is a page? What is a page fault, and how is it handled?

A

Page: fixed-size data block used to divide a process memory. It enables a process to be partially loaded in RAM.

A page fault occurs when a program tries to access memory of a page not currently loaded.

  1. OS search for the page in memory.
  2. If no space left on RAM, selects unused one and replaces with it.
  3. Program resumes execution.
17
Q

Compare and contrast threads and processes. What are their similarities and differences?

A

Both are of program execution.

  • A process has its own independent memory space, ensuring process isolation but making communication between processes slower.
  • A thread shares memory the same memory space making communications faster but creating possible race conditions.

Similarities: Both execute code and can run concurrently.
Differences: Processes are isolated with their own memory, while threads share memory within a process.

18
Q

What is a deadlock? Provide an example scenario that can lead to a deadlock.

A

Situation in which 2 or more processes are stuck waiting for a resource held by other processes, but those processes never release the resource.

Example:
- Thread A has lock1 and waits for lock2.
- Thread B has lock 2 and waits for lock1.

19
Q

Define a race condition. When does it occur? Illustrate with an example.

A

Occurs when two or more threads try to access and modify shared data without proper synchronization, leading to unexpected results.

Example:
Thread 1 reads a shared variable x (initial value 5).
Thread 2 reads x (still 5) and adds 1 to it, resulting in x = 6.
Thread 1 also adds 1 to the original value of x (still 5), resulting in x = 6.
Both threads think they incremented x correctly, but the final value of x is 6 instead of 7 due to the race condition.

20
Q

What is starvation in process scheduling? How can it be prevented?

A

Starvation occurs when a process keeps continuously getting declined the resources it needs to continue the execution, so it neve gets CPU time. This can be prevented by implementing a fair process scheduling or aging.

21
Q

Explain active waiting. Provide an example of it.

A

Occurs when a thread is continuously checking if the resource is available instead of releasing the CPU.

Example: A thread enters a while loop that does nothing until a condition (like a flag or resource availability) is true