Operating Systems Flashcards

(12 cards)

1
Q

What is an Operating System and what are its main functions?

A

Definition: System software that manages computer hardware and software resources.
Functions:
- Process Management: Manages creation, scheduling, and termination of processes.
- Memory Management: Allocates and deallocates memory space for programs.
- File System Management: Organizes files on storage devices for easy retrieval.
- I/O Management: Manages communication with hardware devices (e.g., keyboard, disk).
- Security: Provides protection for system resources and user data.

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

What is the difference between Kernel Mode and User Mode?

A

Kernel Mode (Privileged Mode):
- Has direct access to all hardware and memory.
- The OS core (kernel) runs in this mode.
- A crash in kernel mode can halt the entire system.

User Mode (Non-Privileged Mode):
- Has restricted access to hardware; cannot access it directly.
- User applications run in this mode.
- Accesses hardware via system calls, which switch to kernel mode.
- A crash in user mode only affects the specific application.

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

What is the difference between a process and a thread?

A

Process:
- An instance of a program in execution (e.g., opening a web browser).
- Heavyweight, with its own separate memory address space.
- Processes are independent of each other.
- Context switching between processes is slow.

Thread:
- A lightweight unit of a process that can be managed independently.
- Shares the memory address space of its parent process.
- Multiple threads within a process share code, data, and files.
- Context switching between threads is fast.

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

Explain different CPU scheduling algorithms.

A

First-Come, First-Served (FCFS):
- Non-preemptive. Processes are served in the order they arrive.
- Simple but can lead to long waiting times (Convoy Effect).

Shortest Job First (SJF):
- Can be preemptive or non-preemptive. Selects the process with the shortest execution time.
- Optimal for minimizing average waiting time but hard to predict burst time.

Priority Scheduling:
- Assigns a priority to each process; higher priority processes run first.
- Can lead to starvation for low-priority processes.

Round Robin (RR):
- Preemptive. Each process gets a small, fixed time slice (quantum).
- Fair and good for time-sharing systems.

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

What is virtual memory and paging?

A

Virtual Memory:
- A memory management technique that provides an illusion of a very large main memory.
- Allows programs to be larger than the physical memory.
Paging:
- The primary method to implement virtual memory.
- Divides virtual address space into fixed-size blocks called ‘pages’.
- Divides physical memory into fixed-size blocks called ‘frames’.
- A ‘page table’ is used to map virtual pages to their corresponding physical frames.

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

What is a deadlock and what are its necessary conditions?

A

Definition: A situation where two or more processes are blocked indefinitely, each waiting for a resource held by another process in the set.

Four Necessary Conditions:
1. Mutual Exclusion: At least one resource must be held in a non-sharable mode.
2. Hold and Wait: A process holds at least one resource while waiting for another.
3. No Preemption: A resource cannot be forcibly taken from a process.
4. Circular Wait: A set of processes {P0, P1,…Pn} exists where P0 is waiting for a resource held by P1, P1 for P2, …, and Pn for P0.

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

What is the difference between a mutex and a semaphore?

A

Mutex (Mutual Exclusion):
- A locking mechanism. It’s like a key to a room (critical section).
- Only one thread can hold the key at a time.
- The same thread that locks the mutex must be the one to unlock it.
- Used for protecting shared resources.

Semaphore:
- A signaling mechanism. It’s like a counter for available resources.
- A counting semaphore allows a certain number of threads to access a resource.
- A binary semaphore (value 0 or 1) acts like a mutex.
- One thread can signal (increment) while another waits (decrements).

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

What is a page fault?

A

Definition: A type of interrupt raised by the hardware when a running program tries to access a memory page that is mapped in the virtual address space but is not loaded into physical memory.

Handling Steps:
1. The OS traps the interrupt.
2. It checks if the memory access was valid.
3. If valid, it finds the required page on the disk.
4. It loads the page into a free frame in physical memory.
5. The page table is updated.
6. The instruction that caused the fault is restarted.

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

What is thrashing?

A

Definition: A condition where a system spends excessive time on paging (swapping pages between disk and physical memory) instead of performing useful work.

Cause: Occurs when processes do not have enough physical memory frames to hold their working set of pages.

Consequence: The CPU utilization drops drastically as the system is constantly waiting for pages to be loaded from the disk.

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

What is a context switch?

A

Definition: The process of storing the state of a process or thread so that it can be restored and resume execution at a later point.

Function: It allows a single CPU to handle multiple processes or threads concurrently.

Overhead: Context switching is pure overhead, as the system does no useful work during the switch. The CPU saves the old state (program counter, registers) and loads the new state.

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

What is inter-process communication (IPC)? Name some mechanisms.

A

Definition: A set of mechanisms that allow processes to communicate with each other and synchronize their actions.

IPC Mechanisms:
- Pipes: A simple channel for one-way communication between related processes.
- Shared Memory: A region of memory shared by cooperating processes. Fastest IPC method.
- Message Queues: A linked list of messages stored in the kernel. Processes can send and receive messages from the queue.
- Sockets: A mechanism for communication between processes on the same or different machines (network communication).

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

What is the role of a file system?

A

Definition: The component of the OS that controls how data is stored and retrieved on a storage device (e.g., hard disk, SSD).

Key Roles:
- Abstraction: Presents files and directories to the user, hiding the physical details of storage.
- Structure: Organizes data in a hierarchical manner (e.g., folders within folders).
- Management: Handles file creation, deletion, renaming, reading, and writing.
- Access Control: Manages permissions to ensure security and data integrity.

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