W2 - Processes (Part I) Flashcards

1
Q

What does the compiler do with source code?

A

It turns source code into an executable containing instructions and data.

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

What does the OS load from an executable file into memory?

A

Instruction and data segments.

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

What two memory areas does the OS create for a running program?

A

The stack (for function calls) and the heap (for dynamic memory).

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

What happens after the OS loads the program into memory?

A

It transfers control to the program by setting the Program Counter (PC) and processor registers. (pc points to instructions segment in memory)

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

What two main responsibilities does the OS have while the program runs?

A

Provide services (like system calls)

Protect the OS and other programs

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

What happens in an OS without processes?

A

It can run only one program at a time.

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

Which operating system is an example of one without true processes?

A

MS-DOS on the IBM PC.

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

Why is having only one running program inconvenient?

A

You can’t multitask.

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

Why is having only one running program inefficient, when thinking about system resources?

A

The CPU becomes idle while waiting for I/O operations which are slower than CPU operations, and it wastes time.

With multiple processes, the OS can switch to another program and keep the CPU busy.

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

What type of I/O is the slowest?

A

Disk I/O.

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

What is throughput in the context of operating systems?

A

Maximizing the amount of calculation and useful work done by keeping the CPU busy.

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

Why do OSes need process abstraction?

A

Early OSes could only run one program at a time, making multitasking impossible and wasting CPU time waiting for slow I/O.

Process abstraction allows multiple programs to run at once, improving convenience and CPU efficiency by increasing throughput.

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

What is a process?

A

An instance of a running program with its own state and system resources.

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

What are some parts of a process’s current state?

A

Memory contents, program counter, stack and heap pointers, CPU registers.

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

What system resources can a process have?

A

Amount of memory, open files, devices in use, and more but not mentioned.

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

What information does the OS keep about processes?

A

Number of processes, process states (e.g., waiting), and resource usage (e.g., opened files).

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

Why does the OS need to keep track of process information?

A

To manage process execution, handle waiting and resources, protect processes, and clean up after termination.

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

What is included in a process’s memory?

A

Program code (read from file)

Data (global/static variables, heap, stack)

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

What is the process context?

A

The data the OS uses to manage a process, inc;luding the Process Control Block.

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

What is the Process Control Block?

A

A data structure used by the OS to store information about a process, including its state, program counter, CPU registers, memory info, and I/O status.

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

How does a process view its own execution?

A

A process runs to completion in sequence, unaware of any interruptions or other processes.

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

How does a user view program execution on a computer?

A

The computer appears to run multiple programs at once, creating the illusion of multitasking.

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

How does the CPU and OS manage multiple processes?

A

The CPU switches between processes, each of which is loaded into different memory locations (e.g., Process A at 5000, Process B at 8000, etc.). The dispatcher is responsible for managing these switches.

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

What are the different views of a process’s execution?

A

Process’s view: Runs sequentially to completion.

User’s view: Multiple programs run at once (multitasking illusion).

CPU & OS’s view: The OS switches between processes using a dispatcher, with each process loaded into separate memory locations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the role of the dispatcher in process management?
The dispatcher is responsible for switching between processes on the CPU, ensuring each process gets a fair share of CPU time.
26
How do we create the illusion of running multiple programs on a single processor?
By multiplexing in time, rapidly switching between processes to give the illusion of simultaneous execution.
27
How does the OS switch from one process to another?
The OS saves the PC, SP, and registers of the current process into its PCB, and then loads these values from the PCB of the new process.
28
What triggers a process switch?
Timer interrupt (time slice ends), Voluntary yield (e.g., sleep()), I/O operations (waiting for input/output), Other triggers like priority changes or resource availability.
29
How does process switching work in a single-processor system?
The OS multiplexes in time, rapidly switching between processes. Each process has a PCB containing the PC, SP, and registers. The OS saves the current process's state and loads the next process's state when switching, triggered by a timer, voluntary yield, or I/O operations.
30
What is an "unprotected model" of process management?
A model where processes can access each other’s data, making sharing easy but compromising security and stability.
31
How does the OS give the illusion that many processes are running at once?
By letting each process think it has exclusive access to shared resources like CPU, memory, and I/O.
32
What problems are introduced when running multiple processes concurrently?
Managing process states, protecting the OS and programs from each other, and scheduling which process runs next.
33
Why is protection important in a concurrent system?
To prevent user programs from crashing the OS or accessing/modifying other programs' data.
34
How does the two state process model work?
Actice processes are in one of two states: Running, or not running.
35
What are the five states in the Five-State Process Model?
New, Ready, Running, Blocked (or Waiting), Terminated.
36
What are some reasons a process might terminate abnormally?
Memory unavailable, protection error, I/O failure, operator/OS intervention, arithmetic error, privileged instruction error, etc.
37
What is the purpose of multiple queues in process management?
To organize processes based on the specific event they are waiting for (e.g., disk I/O, user input, network response).
38
Give examples of different event queues a process might wait in.
Queue waiting for disk I/O, queue waiting for user input, queue waiting for network response.
39
Why would the OS suspend a process?
To free up memory for new processes.
40
What happens to a suspended process?
It is swapped out of main memory, typically onto virtual memory (disk).
41
What are the two new states introduced when supporting suspension of processes?
Blocked/Suspend and Ready/Suspend.
42
What is a Blocked/Suspend process?
A process that is waiting for an event and has been swapped out of memory.
43
What is a Ready/Suspend process?
A process that is ready to run but has been swapped out of memory.
44
What is an event in the context of process states?
An event is something the process is waiting for, such as I/O completion, a signal from another process, or resource availability (e.g., memory or a lock).
45
What affects which processes are suspended or resumed?
Process priority
46
Why does the OS need to track information about each process?
To manage its state, execution, and resume an interrupted process.
47
What information does the OS store in a Process Control Block (PCB)?
Process ID, Parent Process ID, state, priority, program counter, stack pointer, register values, and execution time.
48
What is the role of the Kernel Scheduler in relation to PCBs?
It maintains a data structure of PCBs and selects the next process to run based on the scheduling algorithm.
49
In Linux, how are processes represented in the kernel?
They are stored in a doubly linked list, with each element represented by struct task_struct.
50
What does the kernel represent each process as?
A process control block.
51
What is needed in the hardware to support dual mode operation? (user mode and kernel mode)
- A bit of state (user/system mode bit) - Certain operations / actions only permitted in system/kernel mode. - Transitioning to kernal mode sets system mode and saves users PC, etc. - Transitioning to user mode clears system mode and restores appropriate user PC and other state data.
52
Which transition is more critical from a security perspective, and why?: User mode to Kernel mode or Kernel mode to User mode
User mode to Kernel mode is more critical. This transition elevates a process's privileges, giving it access to sensitive system resources. If not properly controlled, it can lead to privilege escalation attacks, where malicious programs gain unauthorized access to system-level operations or data.
53
When do changes in mode typically occur?
System calls - Process requests a system service e.g. read() Interrupts - An external event triggers a context switch (e.g I/O device, Timer) Traps/Exceptions - Internal event triggers context switch (e.g. divide by zero, protection violation such as segmentation fault)
54
What is a system call?
A system call is a programming interface to the OS that allows a program to request services from the kernel, like reading from a file or managing memory.
55
Do you use system calls directly in your code?
No, you don’t explicitly use system calls. You use higher-level functions in languages (e.g., PHP, Python, C), and these functions internally make system calls to the kernel.
56
What is an example of a system call interface, and what does it involve?
An example is the read() system call, which reads bytes from a file. It involves a file descriptor (fd) and a buffer where the result is stored.
57
Why should it be impossible for a buggy or malicious user program to corrupt the kernel?
System calls are designed to prevent user programs from corrupting the kernel, ensuring that even faulty or malicious code can't affect the integrity of the kernel.
58
What is a trap, and how is it related to system calls?
A trap is a mechanism that switches the CPU from user mode to kernel mode, similar to an interrupt. It is triggered when a system call is made.
59
What is the role of the system call handler?
The system call handler processes the system call by using a table to map the call number to the appropriate handler function.
60
Where are the arguments for a system call typically stored, and how does the handler access them?
Arguments for a system call are stored in the user stack, and the system call handler accesses them during the transition to kernel mode.
61
Why are user arguments copied from user memory to kernel memory during a system call?
To prevent user programs from directly accessing or modifying kernel memory, ensuring system security and stability.
62
What does the system call handler do with user arguments?
It validates them to ensure they are correct and safe to process, preventing errors or malicious behaviour.
63
What happens after a system call is executed, and how are results returned to the user program?
After a system call is executed, the results are copied from kernel memory back to user memory, allowing the user program to access them.
64
How do system calls work, from the moment they are triggered to when they finish?[SUMMARY]
1. The user program makes a system call 2. The system call number (which identifies the specific service the program needs) is placed in a register 3. A trap is triggered by the system call, causing the CPU to switch from user mode to kernel mode 4. The system call handler is invoked. It examines the register to get the system call number and maps it to the correct function using a system call table. 5. The system call handler finds the arguments passed by the user program, usually stored on the user stack. 6. The arguments are copied from user memory to kernel memory to protect the kernel space from being directly accessed or modified by the user program. 7. The kernel validates the arguments to ensure they are correct and safe. 8. The system call is executed in kernel mode (e.g. reading the file). 9. Once the kernel is done, the results are copied back into user memory. 10. The CPU switches back to user mode, allowing the user program to continue executing with the results of the system call.
65
Define Trap
A software generated interrupt that occurs intentionally by the program to request a service from the OS (e.g. making a system call). It's the mechanism that allows user programs to transition from user mode to kernel mode.
66
What causes Traps
Traps are caused by the program itself when it explicitly invokes a system call or tries to handle an error.
67
Define Exception
An event that disrupts the normal flow of the program, and needs to be handled by the OS.
68
What causes Exceptions
Unexpected or abnormnal conditions during the execution of the program. (e.g. division by zero)
69
What is a context switch?
When the OS saves the state of the currently running process and loads the state of another process, allowing the CPU to switch between tasks.
70
What steps are involved in a context switch?
1. The OS gains control (via an interrupt or system call) 2. The CPU switches from user mode to kernel mode (mode switch) 3. The OS saves the state of the current process and loads the state of the new process. 4. The OS updates necessary data structures, like the process control block (PCB) 5. The CPU switches to the new process, resuming execution.
71
When does a context switch occur due to an interrupt?
Triggered by an asynchronous external event. The OS reacts to external events (e.g., hardware I/O, timers) and may switch processes to handle them.
72
When does a context switch occur due to a trap?
Occurs during the execution of an instruction due to an error or exception condition (e.g., divide by zero). The OS handles the error or exception and may switch processes.
73
When does a context switch occur due to a kernel call?
The process explicitly requests a service from the OS (via a system call). The OS switches to kernel mode to execute the requested service and then returns control to the user process.
74
Slide 30 and 31 not done.