P2 L1: Process and Process Management Flashcards
Difference between an application and a process
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.
Describe the Sections of the Address space of a process
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.
Why is the stack a LIFO datastructure?
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!
What is the term that describes the structure of a process in memory?
Address space (Virtual Address space)
What is the function of a page table?
Mapping table of virtual process memory to physical memory. Contains page table entries (virtual address -> physical address)
How is a process represented in the OS (where does it store the information what the process is doing)?
In the process control block (PCB).
What is the PCB and what is it used for?
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)
What parts does the PCB have?
- 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, …)
When is the PCB updated?
- 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)
What is a context switch
Mechanism used by the operating system to switch the execution from the context of one process to the context of another process.
Name negative effects of context switch
- 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 can a process continue at the same location when it got an interrupt?
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.
What is the difference between fork() and exec()
- 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.
What are the tasks of the CPU scheduler
- Scheduling Algorithm: Determines which processes in the ready queue should start executing next (maintain ready queue)
- Preemption: send interrupts and save current context
What is the role and the tasks of the CPU dispatcher
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)