P2L1. Processes and Process Management Flashcards

1
Q

What is a process?

A

An instance of an executing program. (e.g., In our toy shop metaphor, a process is like an order of toys.)

It has a state of execution (program counter, stack), parts and temporary holding area (data, register state, occupies state in memory), and may require special hardware (I/O devices)

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

How does an operating system represent a process?

A

An address space is an “in memory” representation of a process.

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

What is an application?

A

A program on disk, in flash memory, or in the cloud. It’s a static entity (i.e., it’s not executing) in contract to a process, which is an active entity.

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

What happens when an application is launched?

A

It’s loaded in memory and starts executing, then it becomes a process.

A process is an active entity, in contrast to an application, which is a static entity.

If the same program is launched more than once then multiple processes will be created. These processes will be executing the same program but they will have different state.

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

What does a process look like?

A

A process encapsulates all of the state of a running application (code, data, variables, etc.) Every element of the process state needs to be uniquely identified by it’s address.

An address space is an abstraction used to encapsulate all the process state.

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

What is an address space?

A

An address space is an abstraction used to encapsulate all the process state.

The address space is defined by a range of addresses from v0 to vMax. These are called virtual addresses because they don’t have to correspond to actual locations in the physical memory.

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

What is the relationship between virtual address space and physical address space?

A

The memory management hardware and the operating system components responsible for memory management (e.g., page tables) maintain a mapping between the virutal addresses and the physical addresses. This mapping decouples the layout of the data in the vitual address space with the layout of the data in the physical address space. That allows physical memory to not be dictated to by the data layout of processes that are executing.

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

If two processes, P1 and P2, are running at the same time, what are the virtual address space ranges they will have?

  • P1: 0 - 32,00, P2: 32,001 - 64,00
  • P1: 0 - 64,000, P2: 0 - 64,000
  • P1: 32,001 - 64,000, P2: 0 - 32,00
A

P1: 0 - 64,000, P2: 0 - 64,000

Both P1 and P2 can have the exact same virtual address space range. The operating system will map P1 and P2’s virtual addresses to distinct physical addresses.

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

How does the OS know what a process is doing?

A
  • program counter
  • CPU registers
  • stack pointer

The OS maintains a process control block (PCB) to manage all of this data.

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

What is a program counter?

A

A program counter indicates where the process is in a sequence of program instructions. It is maintained on the CPU in a register while a process is executing.

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

What is a CPU register?

A

A CPU register holds values necessary during process execution.

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

What is a stack pointer?

A

The top of the stack is defined by the stack pointer. The stack exhibits last in first out behavior so we need to know the top of the stack to properly add/remove items.

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

What is a process control block (PCB)?

A

A data structure that the OS maintains for every process it manages.

The PCB is created and initialized (e.g., the program counter will be set to the first instruction) when a process is created.

Some fields are updated when a process state changes (e.g., it requests more memory and virual address space is updated)

Some fields change too frequently (e.g., process counter) and may only be updated under certain conditions.

The CPU has a dedicated register to track the current program counter for the currently executing process. The CPU program counter gets updated on every instruction. The OS is responsible for collecting all the information the CPU maintains for a process and store it in the process controll block structure whenever a process is no longer running on the CPU.

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

How is a process control block (PCB) used?

A

When an OS manages a process it stores it PCB in memory. When the process is running the CPU registers will hold values that correspond to the state of PCB-P1. When P1 is interrupted or finishes and P2 starts running, the OS will save PCB-P1 in memory and restore PCB-P2 by updating the CPU registers with values that correspond to the state of PCB-P2.

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

What is a context switch?

A

The process control blocks for each process are stored in memory and the values in the CPU registers will change depending on which process is currently executing.

A context switch is the mechanism used by the operating system to switch the CPU from the context of one process to the context of another process.

Context switches are expensive!

  • direct costs: number of cycles that have to be executed to load and store all the values of the process control blocks to and from memory.
  • indirect costs: cache misses, which require visits to memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What states can a process be in?

A
  • new
  • ready
  • running
  • waiting
  • terminated

A process can be running or idle.

When a process is running it can be interrupted and context switched.

When a process is idle it’s in a ready state (ready to execute) but it’s not the current process running on the CPU.

At some point the CPU scheduler will schedule that process to run again.

17
Q

The CPU is able to execute a process when the process is in which state(s)?

A
  • running
  • ready
18
Q

What mechanisms exist for process creation and how do they work?

A
  • fork: copies the parent process control block (PCB) into new child PCB. the child continues execution at the instruction immediately after fork b/c both the parent and the child contain the exact same values in their PCB, which includes the program counter.
  • exec: replaces the child PCB. loads new program and starts from first instruction.
19
Q

What is the role of the CPU scheduler?

A

A CPU scheduler determines which one of the currently ready processes will be dispatched to the CPU to start running, and how long it should run for.

The operating system must:

  • preempt: interrupt a running process and save current context
  • schedule: run scheduler to choose next process
  • dispatch: dispatch a process & switch into its context

CPU resources are precious so the OS must minimize the amount of time it spects on preempting, scheduling, and dispatching.

20
Q

What is a timeslice?

A

The time allocated to a process on the CPU.

21
Q

How does a process end up in the ready queue?

A
  • It makes an I/O request
  • It’s time slice expires
  • When a new process is created via fork (does only the child goes to the ready queue?)
  • It’s waiting for an interrupt…once that occurs it’s placed in the ready queue.
22
Q

What happens to a process during an I/O request?

A

When a process makes an I/O request, the OS delivers the request and places the process on the I/O queue that’s associated with the particular device. The process remains waiting in the queue until the device completes the operation and responds to the request. Once the request is met the process is ready to run again and gets placed in the ready queue.

23
Q

What are inter-process communication (IPC) mechanisms used for?

What are examples of IPCs?

A
  • transfer data/info between address spaces
  • maintain protection and isolation
  • provide flexibility and performance

Examples:

  • message passing IPC
  • shared memory IPC
24
Q

How does message passing IPC work?

A

The operating system provides a communication channel, like a shared buffer. Processes write (send) / read (recv) messages to/from the channel.

Pros:

  • OS manages

Cons:

  • overhead
25
Q

How does shared memory IPC work?

A

The operating system establishes a shared channel and maps it into each process’s address space.

Processes directly read/write from this memory.

Pros:

  • OS is out of the way so the processes don’t incur any overhead while they’re communicating

Cons:

  • OS is out of the way so the shared memory doesn’t have fixed and well-defined APIs, which can mean using shared memory is more error-prone or developers have to re-implement code to use the shared memory region in the correct way
26
Q

Does shared memory-based communication performs better than message passing communication?

A

It depends.

With shared memory communication the individual data exchange may be cheap b/c it doesn’t require that the data be copied in and out of the kernel like memory passing communication, but the actual operation of mapping memory between two processes is expensive.

So it only makes sense to do shared memory communication if that setup cost can be amortized across many messages.