P2 L1: Process and Process Management Flashcards

1
Q

Difference between an application and a process

A

Application=program code on disk (static). Process=State of program/ application when executing (loaded in memory, active, has program counter for next instruction). Multiple processes for one application with diff. state possible.

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

Describe the Sections of the Address space of a process

A

The Address space of a process has 4 Sections:

  • text: program code (lowest address in process address space)
  • data: global variables
  • heap (heap can be fragmented).
  • stack: LIFO queue with temp. data - function scope variables, return args. Highest address growing down to heap.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is the stack a LIFO datastructure?

A

Memory usage mechanism that allows memory to be used as temporary data storage. Stack pointer is a register that always points to current top of stack memory location.

Function X calls function Y. The local vars from Y are put on top of the stack. When finished executing Y, vars from Y are popped from the stack.
When X executes again, the stack pointer points exactly to X’s variables on the stack again!

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

What is the term that describes the structure of a process in memory?

A

Address space (Virtual Address space)

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

What is the function of a page table?

A

Mapping table of virtual process memory to physical memory. Contains page table entries (virtual address -> physical address)

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

How is a process represented in the OS (where does it store the information what the process is doing)?

A

In the process control block (PCB).

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

What is the PCB and what is it used for?

A

An abstraction maintained by the OS to hold information about a process. How the PCB is implemented depends on the OS! Linux has the task_struct referencing other structures that contain specific parts of the PCB (e.g open files, memory management) –> split up PCB is better for threads (see later)

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

What parts does the PCB have?

A
  • Process state (running, waiting, …)
  • Program counter (address of next instruction. Initially start of program code)
  • The values of CPU registers like the stack counter -> MUST be saved when an interrupt occurs to allow the process to continue in the same state after
  • CPU scheduling info (priority, pointers to scheduling queues)
  • Memory management info (Values of base and limit registers (legal address range for process in physical memory), page tables
  • Accounting information (CPU time used
  • I/O status (I/O devices allocated, list of open files / filedescriptors, …)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When is the PCB updated?

A
  • at runtime when process change states(e.g process allocates memory on heap, changes memory mappings in page table)
  • always when an interrupt occurs (OS job to save the current state) to save registers that update too frequently (like the program counter)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a context switch

A

Mechanism used by the operating system to switch the execution from the context of one process to the context of another process.

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

Name negative effects of context switch

A
  • Direct costs: number of CPU cycles needed to load and store PCB to and from memory (RAM)
  • Indirect costs: cold cache when context switching back to P1 later
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can a process continue at the same location when it got an interrupt?

A

During context switch after receiving the interrupt, the OS stores the value of the program counter of P2 in the PCB of P1 in kernel memory (RAM). When context switching back, the value of the register is restored and the CPU executes from there.

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

What is the difference between fork() and exec()

A
  • fork() creates a new process with new PCB -> EXACT copy of PCB from parent. With new PID
  • exec() REPLACE the current program code the current process executes with a new program (does not create a new process with PID). Just loads a new program into current process address space of the process.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the tasks of the CPU scheduler

A
  • Scheduling Algorithm: Determines which processes in the ready queue should start executing next (maintain ready queue)
  • Preemption: send interrupts and save current context
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the role and the tasks of the CPU dispatcher

A

Transfers (dispatches) the selected process from READY to RUNNING state

How

  • Context switch to new process (save current state ob PCP and save in memory, load PCB of next process)
  • Set the program counter to the new address (PCB of other ready process)
  • Possibly switch to user mode for user-space process (set mode bit in register - see P1L2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you calculate CPU efficiency

A

Total processing time / total CPU time

17
Q

How can a process end up in the ready queue of the CPU scheduler

A
  • Waiting: for I/O –> done
  • Waiting for interrupt which occurs
  • Running: time slice expired (preeemption by scheduler)
  • Running : Interrupt
  • New: process is created via fork()
18
Q

What is the only event the CPU scheduler fires

A

The timer interrupt that it fires to preempt a running process

19
Q

What are the two models of IPC

A

Shared memory & message passing

20
Q

What is the fundamental goal of IPC

A

Transfer data / information between isolated address spaces while maintaining protection and isolation

21
Q

Whats the down and upsides of the two IPC mechanisms?

A

Message Passing:

  • Easy to implement (managed by OS).
  • Overhead (system calls (userspace - kernelspace transition), memory copy)

Shared memory

  • Fast as both can just write to shared address pace (OS is not involved)
  • No well-defined APIs supported by OS. More error prone / devs. have to implement more code
  • Initial setup costs of mapping memory between two processes is EXPENSIVE
22
Q

When to use message passing IPC?

A
  • only few messages to send (setup of mapped memory for shared memory is expensive)
  • easy to implement solution (e.g via API calls)
23
Q

When to use shared memory IPC?

A
  • Max performance
  • enough information is exchanged to offset the initial setup costs of shared memory (setting up the memory mapping between two processes)