OS 1 Flashcards

1
Q

What is an operating system?

A

A main program that ALWAYS runs on the processor from system startup, and manages the execution of other programs

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

What are the steps involved in executing a program?

A
  1. When system starts, execute operating system.
  2. Load additional programs into memory.
  3. Request execution of program using a system call.
  4. Operating system starts execution of program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a system call?

A

A mechanism that allows user-level programs to request services or resources from the operating system’s kernel, such as file operations, memory management, or process control.

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

What are the three elements of a computer system?

A
  1. Users (humans, machines)
  2. Software (application programs, operating system, system programs)
  3. Hardware - CPU, memory, battery, input/output devices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are application programs?

A

Software designed to perform specific tasks or functions for end-users on a computer system, typically operating on top of the system software in a device
- e.g., word processing, web browsing, data analysis

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

What are system programs?

A

Software that manage and support a computer’s core functions, facilitating communication between hardware and application programs

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

What is the CPU?

A

The central processing unit, the primary component of a computer that performs calculations, executes instructions, and manages data processing tasks to run programs and operations

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

What is a device controller?

A

A hardware component managing the communication between the CPU and external devices (such as storage drives, printers)
- translates data and control signals between them

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

What is an interrupt?

A

A signal sent to the CPU by hardware or software to temporarily halt its current operations and redirect its attention to a higher-priority task or event

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

What is a device controller buffer?

A

A temporary storage area that holds data being transferred between a peripheral device and the system’s memory, helping to manage data flow and prevent bottlenecks during communication

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

Describe as an example the process of a computer accessing data on a hard drive. Why is this example inefficient? How can some of these issues be fixed?

A
  1. CPU tells device controller what data it wants to read (writing command + address in device controller registers)
  2. Device controller accesses the hard drive.
  3. Hard drive recovers data on disk and writes it in the device controller buffer.
  4. Device controller tells the CPU that the data is ready using an interrupt.
  5. CPU reads data in the device controller and copies it in memory.

CPU wastes time waiting for I/O operation to complete. CPU performs many copy operations. CPU must treat many interrupts.

By using direct memory access DMA

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

What is Direct Memory Access (DMA)? Provide an example of accessing data on a hard drive using a DMA.

A

A method that allows peripheral devices to transfer data directly and from the system’s memory without involving the CPU

  1. CPU tells DMA what block of data it wants to read (command + start address + size of block it wants in DMA registers)
  2. DMA configures the I/O device controller for every data that must be read.
  3. Device controller accesses the hard drive.
  4. Hard drive recovers data and writes it in the device controller buffer.
  5. DMA reads data in device controller and copies it in memory.
  6. Once all the data is transferred into memory, DMA tells CPU the I/O transfer is completed using an interrupt.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does the CPU interface with the device to coordinate the transfer for DMA?

A

CPU initiates a DMA operation by writing values into special registers that can be independently accessed by the device.

Device initiates corresponding operation once it receives the command from the CPU.

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

CPU Is allowed to execute other programs while the DMA controller is transferring data. Does this process interfere with the execution of user programs? If so, how?

A

Both device and CPU can be accessing memory simultaneously. A CPU might therefore have to compete with the device to access the memory, lowering its speed.

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

What are the advantages of DMA? What are some issues regarding to DMA?

A

Less operations executed by CPU. Less interrupts to treat. CPU can execute other useful code in parallel.

Deciding what to execute while waiting for I/O operation. Providing code to configure hardware devices, treat interrupts. Ensuring program state remains consistent through switches.

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

Describe three general methods for passing parameters to the operating systems.

A
  1. Passing parameters in registers.
  2. Registers pass starting addresses of blocks of parameters.
  3. Parameters can be placed, or pushed, onto the stack by the program, and popped off the stack by the OS.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Provide an example of system components that are difficult to layer?

A

The virtual memory subsystem and the storage subsystem are typically tightly coupled and requires careful design in a layered system due to the following interactions. Many systems allow files to be mapped into the virtual memory space of an executing process. On the other hand, the virtual memory subsystem typically uses the storage system to provide the backing store for pages that do not currently reside in memory. Also, updates to the file system are sometimes buffered in physical memory before it is flushed to disk, thereby requiring careful coordination of the usage of memory between the virtual memory subsystem and the file system.

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

What are some of the specific functionalities of the OS as an intermediary between users/applications and computer hardware?

A

Providing a level of abstraction that hides the details of hardware architecture from applications.

Manages sharing of HW resources among applications and users.

Optimises performance through resource management.

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

What would application developers have to know without operating systems? What effects would this have?

A

Hardware platform details to be able to write applications.
Managing memory and address space.
Manage I/O operations.
Manage communications.
Manage file system.

Time consuming, error prone application development. Low portability, as code cannot be easily used on other HW platforms. Hard to use third-party code and libraries.

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

What is a driver?

A

A software development that allows the operating system to communicate with and control hardware devicesm providing a standardised interface for device functionality

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

What are the 8 main responsibilities of an operating system?

A
  1. Process Management:
    - creating and deleting, scheduling, suspending, resuming, synchronising, inter-process communication
  2. Memory Management:
    - allocating, deallocating memory space; efficient utilisation of memory; kepping track of current memory use and by whom
  3. I/O Management:
    - buffer-caching system, general device-driver interface, drivers for specific HW devices
  4. File Management:
    - mainpulating files, directories; maping files onto secondary storage-disks; free space management and storage allocation; disk scheduling
  5. Protection:
    - ensuring that concurrent processes do not interfere with one another
  6. Error Detection:
    - debugging facilities
  7. Security:
    - against other processes, outsiders
  8. Accounting:
    - using timers, CPU Cycles, main memory usage, I/O device usage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is an interrupt service routine?

A

A specialised function or routine in software that is executed in response to an interrupt, handling the interrupt cause and ensuring the CPU can resume its normal operations afterward

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

What is an interrupt vector table?

A

A data structure that holds the addresses of interrupt service routines (ISRs), allowing the CPU to quickly locate and execute the appropriate ISR when an interrupt occurs

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

Describe an example of a HW device instructing the OS to carry out an operation.

A
  1. Interrupt generated to notify the CPU of something.
  2. OS jumps at predefined address memory corresponding to this interrupt.
  3. OS saves current execution context.
  4. OS checks what caused interrupt.
  5. OS retrieves the address of corresponding interrupt service routine from interrupt vector table.
  6. OS executes the interrupt service routine.
  7. OS resumes execution context.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What are traps/exceptions? For what purposes can they be used?

A

Software-generated interrupts caused by either a software error or by calling a specific assembly function

Calling operating system routines or catching errors

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

What is the trap handler?

A

A routine in the operating system that handles exceptional conditions or events that interrupt the normal execution of a program

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

Describe an example of an application generating a trap and the consequent operations.

A

1.Application generates trap
2. CPU jumps at predefined address in memory corresponding to the trap handler
3. OS saves current execution context
4. OS checks why the trap was generated
5. OS executes the requested service
6. OS resumes the execution context

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

What is the OS Dual-Mode Operation? What is the user-mode? How about the kernel mode? Which operations are executed in which mode?
What is the advantge of this Dual-Mode?

A

A system architecture that allows the CPU to operate in two modes, user and kernel.

Where application run with limited access to system resources.

Where the operating system has full control over hardware and system operations.

Most instructions executed in user mode, but some privileged instructions are only executable in kernel mode, such as accessing memory locations reserved for the OS.

Allows the OS to protect itself and other syste components

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

What is the microkernel approach to system design?

A

Reduces the kernel to only the core functionalities necessary for basic system operation, such as interprocess communication (IPC), basic scheduling, and low-level hardware management

Higher-level services, like file systems, device drivers, and network protocols, are implemented in user space as separate processes, enhancing modularity and fault isolation

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

What are the main advantages of the microkernel approach to system design? How about the primary disadvantages?

A

Advantages:

Adding a new service does not require modifying the kernel

More secure as more operations are done in user mode than kernel mode

Simpler kernel design and functionality typically result in a more reliable OS

Disadvantages:

Overheads associated with interprocess communication (between kernel and user services);

Frequent use of OS’s messaging functions

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

What is the mode bit? How is the mode bit changed?

A

A bit in the CPU’s status register that indicates the current operating mode (user or kernel mode)

A system call changes the execution mode to kernel mode, while returning from the system call resets the mode to user.

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

What are the six main motivations for operating systems?

A
  1. Dealing with diverse CPUs and architectures, organisations.
  2. Transparency, i.e., hiding certain details
    - e.g., location of data in physical memory, physical memory size, processor architecture
  3. Visualisation, i.e., providing a simple, abstract, logical model of system with virtual memory, CPU, disk
    - allows programs to be developed as if they were the sole user of the HW resources
  4. Support for Shared Functionality:
    - well defined abstractions of concepts, providing system calls
  5. Portability:
    - programs written within an OS or API can compile/run on any system supporting that OS/API
    - OS provides a unified machine view, defining a virtual machine
  6. Support for Concurrency:
    - concurrency transparency, where each task essentially has a virtual machine of its own
    - manages and protects tasks from each other
    - ensures efficiency through scheduling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What are system calls? How are they usually available?

A

Programming interface to the services provided by the OS, typically written in a high-level language

Through a high-level Application Programming Interface (API)

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

What is an Application Programming Interface?

A

A set of rules and protocols that allow different software applications to communicate with each other and with the operating system

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

What are the five main types of System Calls?

A

Process management, File management, Memory management, Device manamgement, Communications, Miscellaneous

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

What are the three advantages of an API over system calls? What is a disadvantage?

A

works at higher abstraction level, closer to programs’ needs

may combine many system calls to implement higher level tasks

programs using an API can compile/run on any system supporting the API

adds one more layer, with additional overhead

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

What are two different flavours of operating systems?

A

Real-time OS and Embedded OS

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

What is real-time OS?

A

OS designed to process data and respond to inputs within a guaranteed time frame, ensuring that critical tasks are completed within strict timing constraints

known performance, known bounds on maximum latencies of API calls

real-time control, stringent dependability

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

What is embedded OS?

A

specialised OS designed to run on embedded systems - dedicated devices with specific functions, offering optimised performance, low resource usage, and real-time capabilities

small footprint, low system requirements

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

What is a process?

A

A program in execution, with a context of execution, which owns resources, i.e., has memory and can own other resources such as files

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

Can several processes run the same program?

A

Yes

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

Would several processes running the same program have the same contexts of execution?

A

No

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

What is a thread? What is shared among threads? What is not shared among threads?

A

A dispatchable unit of work within a process

Code, data, files

Registers, stack

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

What five things is a process defined by?

A
  1. Program code
  2. Stack - region of memory used to store function calls, local variables, control information
  3. Heap - region of memory used for dynamic memory allocation, where memory is allocated and freed at runtime
  4. Data - global variables whose size are unknown
  5. Current state of execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What are the five process states?

A
  1. New - process being created
  2. Ready - process waiting to be assigned to a CPU
  3. Running - process instructions are being executed
  4. Waiting - process is waiting for some event to occur
  5. Terminated - process has finished executing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Where are the local variables of a process stored?

A

in the stack

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

What does a process control block (PCB) do? List the things that the PCB keeps track of.

A

Records information associated with a process’ context of execution

Process state;

Program Counter (location of next instruction to execute);

CPU registers (contents of all process-centric registers);

CPU scheduling information (priorities, scheduling queue pointers);

Memory-mangement Information (memory allocated to the process);

Accounting information - CPU used, clock time elapsed since start, time limits;

I/O status information - I/O devices allocated to process, list of open files

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

What is a context switch?

A

The saving of the state of a process whose execution is to be suspended, and the reloading of this state when the process is to be resumed

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

How are processes created? How are processes generally identified? Can parent processes share their memory or resources with their children processes?

A

Parent processes create children processes, which in turn create other processes, forming a tree of processes.

Through a process identifier (pid)

Yes

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

What are the three resource sharing options, two execution options, and two address space options?

A

Parent and children share all resources. Children share subset of parent’s resources. Parent and child share no resources.

Parent and children execute concurrently. Parent waits until children terminate.

Child is a copy of the parent. Child has a new program loaded into its address space.

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

What is the Portable Operating System Interface (POSIX)? What four things does it provide?

A

set of standards defining a consistent application programming interface (API) for maintaining compatibility between different Unix-like operating systems

  1. Host language, compiler (C)
  2. Programming Interface Definition FIles
  3. Programming Interface Implementation Binary or Code
  4. Run-time System (OS)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

How can an identicaly copy of a process be created (i.e., a child)? What is the sole thing that varies between the two processes? What is shared between the parent and child?

A

By the parent calling the fork() operation

The return value of the fork() operation: 0 for the child, child-pid for the parent

Address space (variables, memory, file descriptors), program counter (next instruction to execute), process state (open files, signal handlers, etc)

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

What is execlp()?

A

An instruction that overwrites the calling process with its argument (an executable program), meaning that the code following it is never reached

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

What is perror()?

A

A generic error printing routing

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

How are the child and parent independent?

A

Child can execute different code/instructions, close or modify resources independently, terminate independently of parent process

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

What does exit(status) do? How about wait()? What does wait return? How about waitpid()?

A

Terminates the process

Blocks until one of children exit

PID of terminated child

Blocks until a specific child (specified in argument) changes its state

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

What is blocking wait? How can it be done?

A

Parent waits for child to terminate, blocking until child finishes

through wait()

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

What is polling wait? How can it be done?

A

Parent checks periodically if the child has terminated without blocking, allowing it to perform other tasks in between checks

waitpid(child, &status, WNOHANG), which checks if the specified child process has terminated, but does not block

WNOHANG flag makes the call non-blocking, so the parent can perform other activities between checks, such as executing code or handling multiple tasks

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

How can process be terminated?

A

Processes can terminate themselves through exit(), with exit() returning status value from child to parent if parent was waiting.

Alternatively, parent may terminate execution of children processes through abort/kill

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

What is cascading termination?

A

The child being terminated automatically because the parent was.

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

What is a zombie?

A

A child process that has no parent waiting upon its termination, i.e., that invoked wait()

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

What is an orphan?

A

A child process that had its parent terminated without having invoked wait()

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

What are two models for interprocess communication?

A

Message Passing and Shared Memory

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

What is message passing? Are messages blocking or non-blocking? What is rendez-vous communication in the context of message passing? How can asynchronous communication be carried out? What can happen when the buffer is full? What happens if the producer is not blocked and the buffer is full?

A

Producer process sends a message to the kernel, which then forwards the message to the target process

Can be both

Where both the sending and receiving are blocking, and communicating processes synchronise on the transmission

Through the use of a temporary queue or buffer being used to hold items temporarily

The producer may be blocked

Consumers see most recent data, miss old one

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

What is shared memory?

A

Processes share a portion of their address space, so messages can be passed through this shared memory.

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

Similarities between iOS and Android? Differences?

A

Similarities:

Based on existing kernels (Linux, Mac OS X);
Architectures use software stacks;
Provide frameworks for developers

Differences:
iOS closed-source, Android open-source;
iOS developed in Objective-C, Android in Java;
Android uses virtual machine, iOS executes code natively

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

Is the DMA a software or hardware component? Is the DMA part of the operating system? Does the DMA replace I/O controllers?

A

Hardware

No, it is not.

No, it does not.

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

Could a DMA negatively impact the execution time of a program?

A

Yes

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

What mode is a CPU in after an interrupt?

A

Kernel mode

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

Through what mechanism are system calls implemented?

A

Traps

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

Explain the different steps involved in the execution of a system call

A

Process puts the code of the sys call in a register.

It generates a trap that switches the
execution mode from user mode to kernel mode.

The kernel executes the right system call using the
system call code. \

The kernel restores the mode bit so that the execution resumes in user mode.

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

What is synchronisation?

A

The limitation of possible program traces by coordinating execution such that certain conditions are satisfied.

E.g., certain invariant is satisfied and/or execution has some desired property

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

What is an invariant?

A

an assertion that holds at all control points, such as mutual exclusion being maintained or y being less than or equal to x

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

What does action synchronisation rely on?

A

Action counting and invariants on the counting

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

If A is an action in a program, what does cA denote?

A

The number of completed executions of A

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

What is a topology invariant?

A

An invariant derived directly from the program text

E.g., two actions always occuring one after the other

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

What two things is action synchronisation specified by? What are such inequalities referred to as?

A

Inequalities on:

  1. Action counts
  2. Program variables directly related to this counting

Synchronisation conditions or synchronisation invariants

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

What does P(s) refer to? How about V(s)?

A

P(s): <await(s>0)>; s=s-1;

V(s): <s = s + 1>

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

What are the primary two semaphore invariants? What invariant arises from these two?

A

S0: S >= 0
S1: s = s0 + cV(s) - cP(s)

S2: cP(s) <= s0 + cV(s)

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

What is the progress property of semaphores?

A

Blocking is only allowed if the safety properties would be violated

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

What is the action synchronisation solution in general? Specifically, give a collections of tasks/threads executing actions A,B,C,D and the synchronisation:

SYNC: a * cA + c * cC <= b * cB + d * cD + e for non-negative constants a,b,c,d,e

A

Introduce a semaphore s, s0 = e and replace:

A -> P(s)^a; A
C -> P(s)^c; C
B -> B; V(s)^b
D -> D; V(s)^d

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

What does sem_t *sem declare?

A

A pointer to a semaphore object, which will be used for synchronization.

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

What function is used to open and create a named semaphore?

A

sem_open(name, flags, mode, init-val)

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

In sem_open, what does the name parameter represent? What does the flags parameter in sem_open determine? What is the purpose of the mode parameter in sem_open? What does the init-val parameter in sem_open define?

A

A system-wide unique name for the semaphore.

The operation to be performed.

To specify the file permissions.

The initial value of the semaphore.

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

What function is used to close a semaphore in the current process while keeping it accessible to others?

A

sem_close(sem)

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

Which function removes a named semaphore from the system? When is a named semaphore fully removed from the system?

A

sem_unlink(name)

When no process is using it.

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

What does sem_init(sem, pshared, init-val) do? In sem_init, what does the pshared parameter indicate?

A

Initializes an unnamed semaphore.

Whether the semaphore is shared across processes or just threads within a process.

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

What function is used to destroy an unnamed semaphore? What happens if you use a semaphore after it has been destroyed with sem_destroy?

A

sem_destroy(sem)

It must not be used, as its resources are released.

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

What does sem_wait(sem) do?

A

Attempts to decrement (lock) the semaphore; if the semaphore value is greater than zero, it decrements it. If the value is zero, it blocks until the semaphore becomes available.

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

How does sem_trywait(sem) differ from sem_wait(sem)?

A

sem_trywait does not block; it attempts to decrement/lock the semaphore and returns an error if not possible.

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

What is the purpose of sem_post(sem)?

A

To increment the semaphore and wake one waiting thread if any are blocked.

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

How can you retrieve the current value of a semaphore? In sem_getvalue, what does a negative semaphore value represent?

A

By using sem_getvalue(sem, &val).

The number of waiters (the length of the waiting queue).

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

When is busy-waiting accepted? What is the condition for busy-waiting to work as expected?

A

When:

  1. Waiting is guaranteed to be short in comparison to the cost of context switching
  2. There is nothing else to do

The tests in the while and locking the mutex are executed atomically

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

What is a deadlock state? How is it typically proven that a deadlock does NOT exist?

A

A system state in which a set of tasks is blocked indefinitely

Proof by contradiction; Assume deadlock occurs, investigate all task sets that can be blocked at the same time, show a contradiction;

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

What are the three main ways of preventing deadlocks?

A

Always let critical sections terminate
- always call unlock(m) after lock(m)

Avoid cyclic waiting
- avoid P or lock operations that may block indefinitely between lock(m) and unlock(m)
- use a fixed order when calling P-operations on semaphores or mutexes

Avoid greedy consumers
- P(a)k should be an indivisible atomic operation when tasks compete for limited resources

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

Give an example of cyclic waiting for three tasks T1, T2, T3 with three mutexes m1, m2, m3

A

T1 blocked on P(m2), T2 blocked on P(m3), T3 blocked on P(m1), leading to deadlock

97
Q

What does the invariant of condition synchronisation refer to? What does it require in terms of different processes?

A

A combination of execution state

Explicit communication (signalling) between processes

98
Q

What are the two principles of condition synchronisation?

A

Checking and blocking where a condition may be violated

Signalling waiters where a condition may have become true

99
Q

What does var cv: Condition represent in condition synchronization?

A

A condition, often associated with a Boolean expression in terms of program variables.

100
Q

What are the four basic operations on a condition variable (cv)?

A

wait, signal, sigall, and empty.

101
Q

What does the wait(…, cv) operation do?

A

Suspends the execution of the caller.

102
Q

What does the signal(cv) operation do?

A

Frees one process/thread suspended on wait(cv); does nothing if there are no suspended processes.

103
Q

What is the effect of the sigall(cv) operation?

A

Frees all processes suspended on wait(cv).

104
Q

What does the empty(cv) operation check?

A

Whether there are no processes suspended on wait(cv), returning true or false.

105
Q

What does pthread_cond_t cond = PTHREAD_COND_INITIALIZER; do?

A

Statically initializes the condition variable cond.

106
Q

What is the purpose of pthread_cond_init(&cond, attr);?

A

Dynamically initializes cond with optional attributes attr (or NULL for defaults).

107
Q

What does pthread_cond_destroy(&cond); do?

A

Destroys the condition variable cond, freeing its resources.

108
Q

How does pthread_cond_wait(&cond, m); work?

A

Blocks the calling thread until cond is signaled, releasing and reacquiring the mutex m.

109
Q

How is pthread_cond_timedwait(&cond, m, exp); different from pthread_cond_wait?

A

It unblocks after the time exp if no signal is received, returning ETIMEDOUT.

110
Q

What is the purpose of pthread_cond_signal(&cond);?

A

Wakes up one thread waiting on cond.

111
Q

What does pthread_cond_broadcast(&cond); do?

A

Wakes up all threads waiting on cond.

112
Q

What is a monitor? What does the data record? Under what condition are the operations of the monitor executed?

A

An object that contains a combination of data and operations on that data

The state of the monitor

Mutual exclusion, i.e., only one task can be inside the monitor at any one time

113
Q

What three things does a monitor do?

A

Encapsulate relevant shared variables

Provide well-defined operations on shared variables

Provide exclusion

114
Q

What are the four signalling disciplines?

A

Signal and exit

Signal and continue

Signal and wait

Signal and urgent wait

115
Q

How does signal and exit work? Is sigall supported? Must the condition hold after the signal?

A

The task executing a signal exits the monitor immediately, and monitor is given to a waiter on that variable, if any.

No

Yes

116
Q

How does signal and continue work? Must the condition hold after the signal?

A

Task executing a signal continues to use that monitor until a wait or until the end of the routine. Any task released by signal competes with the other tasks to obtain monitor access again.

No

117
Q

How does signal and wait work? Must the condition hold after the signal?

A

The task executing a signal is stopped in favour of the signalled process. Signaller waits to access the monitor after the signal and competes with all other tasks. Similar to signal and exit.

Yes

118
Q

How does signal and urgent wait work? Must the condition hold after the signal?

A

Task executing a signal is stopped in favour of the signalled process. Signaller waits to access the monitor again after the signal but does not compete with all other tasks again, as it has priority over them.

Yes

119
Q

What is the minimum number of semaphores required to enforce 5 synchronization conditions involving 2 global variables and 9 local variables manipulated in 15 threads? Assume we only use action synchronization.

A

5

120
Q

What is the Dining Philosopher Problem?

A

A synchronization problem where philosophers share forks to eat. They must acquire two forks but risk deadlock (all waiting), starvation (some never eat), or conflicts over resources.

Use mutexes, semaphores, or resource acquisition strategies to avoid deadlock and starvation.

121
Q

What is meant by a task being blocked?

A

That it is waiting on a blocking synchronisation action

122
Q

When is a set of tasks D considered deadlocked? Three conditions:

A
  1. All tasks in D are blocked or terminated
  2. There is at least one non-terminated task in D
  3. For each non-terminated task t in D, any task that might block t is also in D
123
Q

What are four program conditions that may lead to deadlock?

A
  1. Mutual exclusion
  2. Greediness (holding and waiting)
  3. Absence of preemption mechanisms
  4. Circular waiting
124
Q

What two types of resources have their access associated with deadlocks?

A
  1. Consumable resources that are taken away upon use.
  2. Reusable resources that are given back after use.
125
Q

What are a great model for the analysis of deadlocks? What are two types of these models?

A

Graphs

Wait-for graphs and dependency graphs

126
Q

What two things do wait-for graphs model best? How about dependency graphs?

A

Consumable resources and condition synchronisations

Reusable resources and action synchronisations

127
Q

What do the nodes in wait-for graphs represent?

How about edges?

What does an edge p1->p3 represent?

What are the edges labelled with?

What does the wait-for graph capture?

A

Tasks, i.e., activities, threads/processes

Wait-for (blocked-on) relationships.

p3 is blocked on p1

Corresponding blocking conditions

A possible dynamic situation (reachable system state), whose existance must be proven.

128
Q

When is a deadlock possible in a wait-for graph?

A

Only if there is a CYCLE in the wait-for graph and NO TASK OUTSIDE any cycle can UNBLOCK a task in the cycle.

129
Q

How can one use a wait-for graph to prove the abscence of deadlocks?

A

Through a proof by contradiction.

Assume one task T in the graph is blocked on a certain action. Add T to a new graph

Add each task T’ that can unblock T to the new graph, creating an edge from T’ to T labeled with the blocking condition it may unblock.

Check whether each task T’ can possible be blocked on an action. If yes, repeat from 1 with T’.

Once the whole graph is built, check if we are in a deadlock state. If no, we reached a contradiction. If yes, we are in a potential deadlock and we should build a trace showing how we reached that state.

130
Q

What type of graph are resource dependency graphs? What do the nodes represent? How about the edges?

A

Bipartite graphs

Two classes of nodes, one for tasks and one for resources

Three types of edges, depending on type of outgoing and incoming nodes

131
Q

Let p be a task and R a resource. What does the edge p->R represent in a dependency graph? How about R->p? How about p–>R

A

p->R represents that task p is requesting resource R and now waiting for it

R->p represents that task p holds resource R

p–>R represents that task p MAY request resource R

132
Q

What does a resource dependency graph represent? What are three types of events that may change the state?

A

A particular state of the system

A request by a task, An acquisition of a resource by a task, A release of a resource by a task

133
Q

When is a task in a resource dependency graph blocked?

A

When it has an outgoing edge that is not directly removable, i.e., for which the requested resource is not free

134
Q

When is there a deadlock in a resource dependency graph?

A

When after removing non-blocked tasks and all their incoming connections, there rem,ains a set of tasks.

135
Q

What are three active approaches to dealing with deadlocks?

A

Prevention at design time by programmer

Avoidance on system side by dynamically checking to avoid entering risky state

Detection and Recovery by checking only whether we are in a deadlock state, and trying to recover from it

136
Q

What is prevention?

How can dependency graphs be used?

Wait-for graphs?

What are some synchronisation tricks that can be used?

How does preemption play a role?

A

analysing your system using reduced dependency graphs and wait-for graphs at design time to provide a proof that there can never be any deadlock

Make their reductions be empty.

Prevent cycles in the graphs

No circular wait, ensuring termination of critical sections, locking resources in a fixed order, acquiring all resources at once

Preemption of resources must be allowed when needed

137
Q

How does avoidance work?

A

Upon executing each potentially blocking action:

check if an open execution path exists (i.e., that will avoid deadlocks)

if one does not, deny or postpone the action

the check can be carried out with a reduction of the max claim graph

138
Q

What is a maximum claim graph?

A

Dependency graph extended to capture potential future resource claims

139
Q

What is Banker’s algorithm?

What does c[j] represent?

How about max[i,j]?

What is its aim?

A

An avoidance algorithm

Number of resources of type j

Maximum number of resources of type j that may be needed by task i

Synchronising requests such that each taskc an always acquire resources until its specified maximum

140
Q

What does avail[j] represent in the Banker’s algorithm?

How about alloc[i,j]?

How about claim[i,j]?

What are the initial states of all these?

What are the invariants related to these?

A

Number of resources of type j still available?

Number of resources of type j allocated to task i

Maximum number of resources of type j that may still be claimed by task i

Avail[j] = c[j], Alloc[i,j] = 0, claim[i,j] = max[i,j]

Avail[j] = c[j] - Sum of Alloc[i,j] for all i
claim[i,j] = max[i,j] - alloc[i,j]

141
Q

When is a state called open for a task i? How would you specify this mathematically?

A

When all the resources it may claim can be directly given to it

Claim[i,j] is less than or equal to Avail[j]

142
Q

When is a state called safe for a task?

A

When this task can eventually be given its maximum number of resources

143
Q

When is a state called safe?

A

When it is safe for all tasks

144
Q

Assume a safe state, and a new request on resource j by task i. If this request were fulfilled, is it enough to check whether the resulting state is safe for task i to determine whether the resulting state is safe overall? Why or why not?

How could state safety be checked?

A

Yes, because if it is safe for task i, then all resources owned by task i will eventually be returned, reaching a state at least as safe as the current one.

Repeat the following:
1. Find an open task
2. Remove it, and all its claims (graph reduction)
3. Until task i is found to be open

145
Q

What does the NextOpen function do?

What happens if no task can proceed in the NextOpen function?

In the NextOpen function, what does Alloc[i] != 0 check?

What does Claim[i] <= Avail ensure in the NextOpen function?

A

It finds the index of the first open task that can proceed based on the available resources and claimed resources.

The function returns N, indicating no open task is available.

It checks if the task i is active (has allocated resources).

It ensures the remaining resource claim of task i can be satisfied with the current available resources.

146
Q

What is the precondition for calling the Safe function?

A

Avail >= req must hold, meaning the available resources can cover the requested resources.

147
Q

What does the line Avail = Avail - req in the Safe function simulate?

How does the Safe function check if the system remains safe after allocation?

What does Avail = Avail + Alloc[k] in the Safe function do?

Why is the Claim[k] reset to Max[k] when task k completes?

What does the Safe function return?

What happens inside the while loop in the Safe function?

A

It reduces available resources by the amount requested by task i.

It simulates completing tasks using the NextOpen function and checks if resources can satisfy all remaining claims.

It simulates releasing all resources held by task k back to the available pool.

To indicate that task k has finished and no longer needs resources.

true if the system is in a safe state after allocation, otherwise false.

The function iterates through open tasks, simulating their completion, until the system is safe or no open tasks remain.

148
Q

What is the purpose of the Safe function in the Banker’s Algorithm?

A

To ensure that allocating resources to a task will not lead the system into an unsafe state.

149
Q

What is the Banker’s Algorithm, and how does it work in detail?

A

The Banker’s Algorithm is a deadlock avoidance method that ensures safe resource allocation by simulating whether a system can remain in a safe state after granting resource requests. It works by checking if resource allocation to processes is possible without causing a system-wide deadlock. It concerns one particular request, and simulates whether granting that request would lead to a safe state or not?

150
Q

What does the detection algorithm do during execution?

What is required for deadlock detection during execution?

What is a major drawback of repeated monitoring and recovery from deadlock?

Where can the recovery algorithm be executed?

What are the two approaches for killing tasks in a deadlock set?

What does rolling back to a safe state require?

What does preempting resources in a deadlock involve?

A

It is invoked periodically to check if deadlock occurs.

An algorithm to examine the state upon execution of a blocking action, and an algorithm to recover from a deadlock.

It causes large overheads.

Locally, inside the task that last blocked or globally, through a recovery policy.

Kill all tasks, and kill some tasks based on specific criteria.

An alternative execution path must exist, and the state must be recorded at checkpoints (sufficient history information to roll back).

Deallocating resources from tasks in the deadlock state.

151
Q

What are the different schemes for the prevention approach?

A

Requesting all resources at once.

Preemption.

Resource ordering.

152
Q

What are the major advantages of the prevention approach?

A

Works well for processes that perform a single burst of activity.

No preemption necessary.

153
Q

What are the major disadvantages of the prevention approach?

A

Inefficient.

Delays process initiation.

Future resource requirements must be known by processes.

154
Q

What are the major advantages of the avoidance approach?

What are the major disadvantages of the avoidance approach?

A

No preemption necessary.

Future resource requirements must be known by the OS.

Processes can be blocked for long periods.

155
Q

What are the major advantages of the detection approach?

What are the major disadvantages of the detection approach?

A

Never delays process initiation.

Facilitates online handling.

Inherent preemption losses.

156
Q

What are the resource allocation policies for the three approaches (Prevention, Avoidance, and Detection)?

A

Prevention: Conservative; undercommits resources to ensure that deadlocks cannot occur. It enforces strict rules to avoid unsafe states by limiting resource allocation.

Avoidance: Balances between prevention and detection by cautiously allocating resources to maintain at least one safe path. The system dynamically analyzes the current state and future requests to avoid potential deadlocks.

Detection: Very liberal; resources are granted whenever possible without regard to potential deadlocks. This approach focuses on detecting and resolving deadlocks after they occur.

157
Q

What is a resource in the context of processes?

A

Anything needed for a process to run, such as main memory, space on a disk, or the CPU

158
Q

How does an OS abstract resources? What represents disk space? How about memory use? How about CPU use?

A

By creating simplified representations of hardware:

Files represent disk space
Processes represent memory use
Threads represent CPU use

159
Q

How does an OS manage resource sharing? Three ways

A

Space sharing (allocates different resources to different programs simultaneously)

Time sharing (allows programs to share resources over time by switching between them)

OS Isolation Mechanisms (protect resources and programs, ensuring they do not interfere with each other or compromise system stability)

160
Q

What are the four main components of the OS kernel in logical OS organization?

A

Process and thread manager.

File manager.

Memory manager.

Device manager.

161
Q

What does the process and thread manager interact with?

A

Memory manager for virtual memory management.

Processor(s) for scheduling and task execution.

162
Q

What does the file manager interact with?

A

Memory manager for performance improvement (e.g., caching data).

Device manager for accessing storage devices.

163
Q

What is the role of the memory manager in logical OS organization?

A

Coordinates with the process manager for virtual memory (e.g., scheduling and memory allocation).

Interacts with the file manager for performance improvement (e.g., data caching).

Manages access to main memory.

164
Q

How do modules in the OS kernel coordinate their activities?

A

All modules (process manager, file manager, memory manager, device manager) interact to ensure efficient resource allocation and system performance.

165
Q

What are the two requirements for process execution?

A

A running program must be brought from disk to main memory

Each process must have a distinct address space for protection

166
Q

What are the six characteristics of a good memory from the user/program perspective?

A

Non-volatile.

Private for a program (protected).

Infinite capacity.

Zero access time.

Simple to use.

Cheap.

167
Q

What are the characteristics of CPU registers in the memory hierarchy?

A

They have the fastest access speed (1 clock cycle)

They are limited in size

They store the most frequently accessed data

168
Q

What are the characteristics of primary memory (main memory)?

A

They have direct access (around 100 clock cycles)

They are relatively larger than CPU registers

E.g., RAM

169
Q

What are the characteristics of secondary memory (storage devices)?

A

Accessed through I/O operations

Very cheap and very large in size

Data is stored for long periods

Much slower than CPU register memory

E.g., disk, tape, solid state devices

170
Q

How does the memory hierarchy manage frequently and less frequently used information?

A

More frequently used information moves to faster memory, such as CPU registers and primary memory

Less frequently used information is stored in slower memory, such as secondary memory

171
Q

How does the memory hierarchy balance speed and storage size?

A

Faster memory (e.g., CPU registers) has smaller size and higher cost.

Slower memory (e.g., secondary storage) has larger size and lower cost

Data is moved up or down the hierarchy based on access frequency.

172
Q

How does the OS exploit the memory hierarchy during updates?

Describe the common characteristics of upward moves/updates.

Do the same for downward moves/updates.

A

Updates are first applied to upper memory.

Usually copy operations, keeping the image in both higher and lower memory.

Usually destructive to save space in upper memory by destroying the image in upper memory, and updating the image in lower memory.

173
Q

What are the characteristics of single-programmed memory management solutions?

How about multi-programmed memory management solutions?

A

One program runs at a time and uses all available memory.

Multiple programs share memory and CPU resources, improving overall resource use and efficiency.

174
Q

What is a single-programmed solution in memory management?

A
  1. Program loaded entirely into main memory (MM) and allocated as much contiguous memory space as needed.
  2. Once in MM, program stays there until execution stops
175
Q

Issues with single-programmed solutions

Advantages?

A

Issues:

No support for multiprogramming.

Large context-switch overhead.

If a program does not fit in memory, it cannot be executed.

Advantages:

Simple hardware requirements (base address and limit registers).

Easy protection between the operating system and processes, as well as between processes.

176
Q

What are fixed partitions in memory management?

A

Memory is divided into fixed partitions, with one process per partition

Partitions may have different sizes, determined at OS initialization.

Each process can only access its assigned partition for protection.

177
Q

What are the disadvantages of fixed partitions?

A

Entire program must be stored in main memory.

Internal fragmentation

178
Q

What is internal fragmentation?

A

Internal fragmentation occurs in fixed partitions when a program doesn’t fully use the allocated partition space

Small partitions lead to long turnaround times, large partitions result in wasted memory

179
Q

What are dynamic partitions in memory management?

A

Partition size is not fixed and is based on process size.

Eliminates internal fragmentation.

However, external fragmentation may occur.

180
Q

What is external fragmentation?

A

External fragmentation occurs when free memory is broken into non-contiguous blocks due to repeated allocation and deallocation.

181
Q

What is the First-Fit allocation scheme for dynamic partitions? Adv, disadv

A

Allocates the first partition that is big enough for the process.

Advantages: Faster allocation.

Disadvantages: Wastes more memory space due to larger leftover partitions

182
Q

What is the Best-Fit allocation scheme for dynamic partitions? Adv, disadv

A

Allocates the smallest partition that fits the process requirements

Advantages: Produces the smallest leftover partition, making better use of memory.

Disadvantages: Takes more time to find the best fit.

183
Q

How does First-Fit memory allocation track holes?

How about Best-Fit memory allocation?

A

FF:

Orders the list by memory location.

Finds the first available block large enough for allocation.

BF:

Orders the list by block size.

Finds the smallest block that can accommodate the process.

Provides better memory utilization but takes more time.

184
Q

What is the Next-Fit allocation scheme?

A

Starts each search at the point where the previous search stopped.

Results in a faster search but slightly worse memory utilization compared to First-Fit.

185
Q

What is the Worst-Fit allocation scheme?

A

Allocates the largest available partition for the process.

Results in performance similar to First-Fit and Next-Fit.

Leaves the smallest possible remaining partitions.

186
Q

What statistics do optimized allocation schemes in memory management use? What do they aim to do?

A

Utilize statistics like average process size and other metrics.

Aim to improve memory utilization and reduce fragmentation.

187
Q

When does the release of memory space occur?

How does memory release work for fixed partitions?

How does memory release work for dynamic partitions?

A

When a process terminates or suspends

The memory manager resets the status of the memory block to “free.

Tries to combine free areas of memory:

If a block is adjacent to another free block, combine the two.

If a block is between two free blocks, combine all three.

If a block is isolated from other free blocks, create a new table entry.

188
Q

How does the memory manager handle relatable dynamic partitions?

A

Relocates programs to gather all empty blocks into one large free memory block.

Solves both internal and external fragmentation problems. Relocation and compaction avoid memory waste. Reduces “insufficient memory” issues.

189
Q

What are the steps of memory compaction?

A
  1. Relocate every program in memory so that they are contiguous.
  2. Adjust every address and reference within each program to account for their new locations in memory.
190
Q

When should compaction be done?

A

When a certain percentage of memory is busy (e.g., 75%).

When there are pending processes.

After a prescribed amount of time.

191
Q

What is a major drawback of memory compaction?

A

Compaction has a very high overhead, requiring each word to be read and rewritten into memory, which may take several seconds.

192
Q

What is complete compaction in memory management?

What is partial compaction in memory management?

What is the minimal data movement strategy in memory management?

A

All processes are relocated to create one large contiguous free memory block. Maximizes free space but involves the most data movement.

Relocates only enough processes to create the required block of free memory. Balances between maximizing space and minimizing data movement.

Moves only the necessary data to create the required block of free memory. Minimizes overhead at the cost of potentially fragmented free memory blocks.

193
Q

How can the location of each process be determined with respect to its original location?

What is the purpose of relocation registers?

What is the purpose of limit registers?

A

Through the use of special-purpose registers.

Contain a value to be added to each address referenced in the program. Ensure correct memory access after process relocation.

Store the size of the memory space accessible to each program. Prevent programs from accessing memory outside their allocated space.

194
Q

What is swapping in memory management?

A

Swapping is carried out when a program must be loaded into main memory (MM) and there is not enough room

It involves moving something else to secondary storage to make room.

195
Q

How is swapping performed?

A

A process is selected to swap out and replaced with another process from secondary storage.

Only parts of the process not already on disk are swapped out.

196
Q

Where are swapped processes placed?

A

In either an arbitrary file in secondary memory or a special partition on disk called the swap space.

197
Q

What are the three main properties of a file system?

A

Persistent across shutdowns

Independent of virtual memory size

Facilitates sharing between users and processes

198
Q

What are the basic requirements of a file system?

A

Naming: Use symbolic names for files

Transparency and portability: Hide hardware details through abstraction

Robustness: Protect against faults

Access control: Ensure authorization and authentication

Security: Protect files and ensure data integrity.

199
Q

What are the user requirements of a file system?

A

Access files using symbolic names.

Capability to create, delete, read, and change files.

Controlled access to system and other users’ files.

Control own access rights.

Restructure files (e.g., moving, copying).

Move data between files.

Backup and recover files.

200
Q

What is a file in a file system? What can it store

A

a logical data storage unit that abstracts physical storage properties

It can store numerical data, character data, binary data, program files.

201
Q

What are permanent attributes of a file? What are some examples?

A

Created upon file creation and always exist (values can be changed)

Type.
Ownership.
Size.
Permanent/temporary flag.
Protection and access rights.
Dates (creation, access, modification).

202
Q

What are temporary attributes of a file? What are some examples?

A

Created and maintained during file access.

Read pointer, write pointer, buffers, open count, locking

203
Q

What does the “temporary flag” attribute represent?

A

0: Normal file.

1: Delete file upon process exit.

204
Q

What are the three file access methods?

A

Sequential Access
Direct/Random Access
Access Through Index Files

205
Q

What is sequential access in file management? What are the allowed operations?

A

Reads bytes/records from the beginning and can only rewind.

Read next: Reads a record and advances to the next position.
Write next: Writes a record and advances to the next position.
Rewind: Resets to the beginning.

206
Q

What is direct/random access in file management? What operations are included?

A

Can jump to any record and read/write

Read/write at a specific record (requires an argument).
Jump to a given record.
Adjust current position (seek).

207
Q

What is access through index files? What are the advantages of indexed access?

A

Built on top of the direct-access method. Involves constructing an index for the file, searching the index to locate the file’s pointer, using the pointer to access the file directly.

Efficient retrieval of records based on logical identifiers (e.g., names or IDs).
Provides faster access compared to scanning the entire file sequentially.

208
Q

What is a directory in file system organization?

A

A file containing information about other files and directories.

209
Q

What is a disk in file system organisations?

A

A disk can be subdivided into partitions, each capable of hosting its own file system.

210
Q

What is a partition in file system organization? Can it involve multiple disks?

A

It represents a subdivided section of a disk.

Yes

211
Q

What is a volume in file system organization?

A

A logical storage space (partition) formatted with a file system

Referred to by a logical drive letter (e.g., C:, D:).

212
Q

Can each partition have its own file system?

A

Yes, each partition can have its own file system, such as NTFS or FAT32, and is associated with a specific drive letter (e.g., C:, D:, E:).

213
Q

What is the relationship between physical disks, partitions, and volumes?

A

Physical disks can be divided into partitions

Each partition is formatted as a volume with its own file system and drive letter.

The drive letters can be referred to as volumes.

Example:
Partition 1 (NTFS) → Drive C:.
Partition 2 (FAT32) → Drive D:.
Partition 3 (FAT32) → Drive E:.

214
Q

What are the semantics of directory operations? Create, Delete, Rename, List, Search

A

Create: Generates an empty structure in a parent directory.
Delete: Removes an entry (file or subdirectory).
Rename: Renames a file or subdirectory.
List: Lists the contents.
Search: Recursively queries directories for a file or subdirectory.

215
Q

What are the UNIx mode of accesses? What are the classes of users?

A

Read (R), Write (W), Execute (X).

Owner: Defines rights of the owner.
Group: Defines rights of a group of users.
Other: Defines rights of any other user.

216
Q

How are UNIX file permissions represented?

A

Permissions are represented as rwx for Read, Write, Execute.

Mapped to numeric values:
rwx = 7
rw- = 6
r-x = 5
And so on…

217
Q

How are UNIX permissions assigned with chmod?

A

Permissions are assigned using numbers for owner, group, and others.

Example: chmod 761 game means:
Owner: Full access (7 = rwx).
Group: Read and Write (6 = rw-).
Others: Execute only (1 = –x).

218
Q

What is the role of the kernel in the conceptual interaction diagram?

A

Opens subdirectories and checks permissions

Creates file descriptors in the Open File Table (OFT)

Provides a pointer to the descriptor for the application process

219
Q

What four things are stored in the Open File Table (OFT)?

A

Owner of the file or directory

Access permissions (e.g., rwx)

Size and blocks or buffers associated with the file

Entries for subdirectories and files

220
Q

What are the levels of abstraction in the layered view of the file system?

A

User Level: Symbolic file names and file system interface.

File System Level:
Directory management (high-level file functions).
Basic file system (open/close functions).

Device Level:
Device organization methods (low-level data access)
Logical block to physical address mapping.

221
Q

How does the hard drive store and access data?

A

Data is stored in sectors (32B to 4KB), grouped into cylinders

Read/write heads are mounted on arms that move across cylinders

Sectors are numbered sequentially from 0 to the total number of sectors on the drive

222
Q

What is the purpose of sectors, cylinders, and read/write heads?

A

Sectors: Memory blocks for data storage.

Cylinders: Vertical alignment of tracks on multiple platters.

Read/Write Heads: Access data on sectors and move between cylinders

223
Q

What is a bootstrap program? Where does it reside?

A

Initial code executed when a computer is powered on or reset
Initializes hardware and loads the operating system into memory

Resides in non-volatile memory (e.g., ROM or flash) to ensure startup without relying on external storage

224
Q

How does booting from the hard drive work?

A

The bootstrap program in ROM:
Loads the Master Boot Record (MBR) from the first hard drive.
Transfers control to the boot program.

The boot program:
Uses the partition table to locate the OS kernel.
Loads the OS kernel into main memory and transfers control to the OS.

225
Q

What are the kernel’s key data structures for booting? What does each do, specifically?

A

Boot-control block contains information about booting the system from a specific partition. Stored in the first sector of the volume.

Volume control block contains the partition table, number of blocks in the file system, and pointers to free blocks.

Directory structure: contains file names and pointeres to corresponding file control blocks for each file

File control block: contains details about ownership, size, permissions

226
Q

What is a volume/ logical drive?

A

A storage area with a single file system, usually denoted by a drive letter such as C, D, or E

227
Q

What happens when a new file is created?

A

A new FCB is allocated and filled with the file’s details

The directory structure is updated with the new file name and FCB information.

228
Q

What happens when a process opens a file?

A

A copy of the File Control Block (FCB) is saved from the disk into the system-wide Open File Table (OFT).

An entry is added to the per-process Open File Table (OFT) in the Process Control Block (PCB), referencing the system-wide OFT

229
Q

What is the system-wide Open File Table (OFT)?

A

Stores FCBs of files currently open by any process

Tracks file usage across all processes

Maintains a counter indicating how many processes have opened each file

230
Q

What happens when a file is opened by multiple processes?

A

Only one entry is created in the system-wide OFT for the file.

Each process has its own entry in the per-process OFT referencing the system-wide OFT

The system-wide OFT counter tracks how many processes have the file open.

231
Q

What happens when a file is closed by a process?

A

The corresponding entry in the per-process OFT is freed.

The system-wide OFT counter is decremented.

If the counter reaches zero:
No process is using the file.
The FCB is removed from the system-wide OFT.

232
Q

How does file reading work in this structure?

A

User space requests data using the read(index) function.

The per-process OFT retrieves the index from the system-wide OFT.

Data is accessed from secondary storage blocks via the FCB.

233
Q

What are the three types of file allocation methods on a disk?

A

Contiguous Allocation:
All blocks of a file are stored together.
Fast for sequential access but requires contiguous free space.

Linked Allocation:
Each block points to the next block.
No need for contiguous space, but random access is inefficient

Indexed Allocation:
Uses an index block to store all pointers to the file blocks.
Efficient for random access but can waste space if the file is small

234
Q

What is the FAT (File Allocation Table) and how does it manage file storage?

A

The FAT (File Allocation Table) is a data structure used by some operating systems, such as DOS and Windows, to manage file storage on a disk. It tracks the allocation of disk blocks to files and manages the sequence of blocks that make up each file.

235
Q

Advantages, disadvantages of contiguous, linked, index allocation of blocks

A

Advantages:
Fast access for sequential reads.
Disadvantages:
Finding contiguous free space is difficult.
Growth of the file may require relocation or over-allocating space.

Advantages:
Files can grow dynamically.
No need to know the file size in advance.
Disadvantages:
Random access is slow.
If a pointer is lost or corrupted, the file is partially unrecoverable

Advantages:
Supports dynamic file growth.
Allows efficient random access.
Disadvantages:
Requires additional space for index blocks.
Can limit file size if the index block is small

236
Q

What is the inode structure in the UNIX file system?

A

Direct blocks: Store data for small files directly in the inode.

Indirect blocks: Pointers to other blocks for larger files.
Single: Points to data blocks.
Double: Points to blocks that point to data blocks.
Triple: Points to blocks that point to other blocks, which then point to data blocks.

237
Q

How does an inode manage large files?

A

Uses direct pointers for the first few blocks.

Switches to indirect pointers for larger files.

Uses multi-level indexing (single, double, triple) to handle very large files efficiently.

238
Q

What is the primary method used for free space management in file systems?

What are the primary challenges with this method?

How do “linked” and “indexed” file allocation strategies manage free space?

A

Free space is managed using a linked list.

Traversing the list and finding a contiguous block of a given size are not easy tasks.

They add and remove single blocks from the beginning of the list.

239
Q

Is a system in an unsafe state for sure going to reach a deadlock?

A

No