Processes Flashcards
What is a process?
A process is a program in execution. Requires CPU resources, memory, I/O, etc.
What is a program?
A program is a set of instructions for performing a specific task. Stored on disk
What is the difference between a process and a program?
A process is simply a program in execution.
A process will always be in any of these 5 states…
Born, Ready, Waiting, Running, Dead
What is a process control block?
A process control block, or PCB, is a block used to store information about a process.
A PCB contains information such as:
The process ID
The process state (its registers, including volatile data such as temporary calculations and its next instruction)
The process address space (space to store data about the process)
The process I/O (a point of access)
What is a process/context switch?
A context switch is the act of changing which process is active. A context switch is almost purely overhead.
In order to do this, the processor must first change the state of process A to waiting, save the context of process B, then change the state of process B to running.
What is the process address space?
The process address space is a method of encapsulation, used to isolate different processes from each other, so that each process has its own private memory that cannot be accessed by other processes.
The process address space consists of the stack, the heap, a data section for static data and a text section for code.
What is the stack?
The stack is a data structure known for its “Last In First Out” property. This means that the most recently added piece of data will be the first to be “popped” out.
The stack is used to manage the execution of a program and to provide a way for functions to communicate with each other and access local variables.
It does this by, for all intensive purposes, “stacking” each function call on top of eachother, to both isolate block-scope variables and to provide a means of returning to the previous function call when finished.
What is the heap?
The heap is a data structure typically located below the stack in the process address space and grows upward as more data is added to it.
The heap is used to store data that is not known beforehand or that may change during the execution of a program.
It is typically used to store data that is allocated dynamically, meaning that the memory is allocated at runtime as needed and is not part of the process’s static memory allocation.
What are the four system calls for a process? (Linux)
Fork
Creates a child process with a unique process ID, and a copy of the ‘parent’s’ address space and all data along with it.
(In modern operating systems, the parent and child share the process space instead)
Exec
Runs an executable file that overwrites the process’s address space with a new program.
Wait
The parent process is put in the “waiting” state until the child process has finished.
Exit
When done, the child process issues the “exit” system call, and the parent process resumes.
What is shared memory?
(Interprocess Communication)
Each process writes into a shared address space. Both processes must make system calls to make the shared memory address space available to both processes.
The processes themselves are now responsible for ensuring they are not writing to the same space in memory simultaneously.
What is message passing?
(Interprocess Communication)
Both processes send data into an agreed “mailbox” that is not part of either of their address spaces.
Shared memory vs Message passing
Shared memory is faster than message passing as only one system call is needed to share the memory.
However, message passing is better for small amounts of data as it avoids the complex issue of needing to set up shared memory.
What is a scheduling algorithm?
A scheduling algorithm is a method used to optimise the amount of time spent on each process.
What is the difference between a first-come-first-served and round-robin scheduling algorithm?
First come first served is an algorithm that prioritises the first processes to be added to the queue, based on their creation time.
Round robin does the exact same. However, round robin employs a time quantum, a fixed amount of time that each process has to complete, before it will be paused and replaced by another process. This ensures that each process gets an equal amount of CPU time.