ECM 1413 Processes Flashcards
- A program:
- is a set of instructions for performing a specific task (passive)
- is stored on disk
- A process:
- An instance of a program in execution (active)
- requires CPU resources, memory and I/O
- Multiple process instances of one program
Why do we use processes?
Modularity
Simplifies OS development
Speedup through parallelism
Subdivision of tasks so they can be ran in parallel
Security and stability through isolation
nodes of the process lifecycle
born
ready
waiting
running
died
Born/new
process created but not admitted
Ready
process in main memory, ready to execute
Running
The process has been allocated to a cpu pool and is currently running
The processor might the running of a process on the grounds of an interrupt or timeout and it is back to the ready state
What is a Pressure Control Block (PCB)
Data structure that stores information, details, metadata, about a block. It is important in context switching
Usually every process has parent (except the first). As such, each process stores the ID of the parent process
PCB is the Kernel’s representation of the process
Context Switching. Context:
the current state of the process (the files it has access to, the condition of the variables in the process)
- A context switch is pure overhead - Time required varies with factors like the number of registers that must be copied
To stop running process 1 and start process 2:
1) Change the state of process 1 from running to ready
2) Save the context of process (since it’s back in ready, we will need to use it later again)
3) Load the context of process 2
4) Change the process scheduling state of process 2
This whole process is referred to as a context switch or process switch
Overhead:
any combination of excess or indirect computation time, memory, bandwidth, or other resources that are required to perform a specific task.
With too few context switching:
- There will be the starvation of some processes. No fairness between the processes as some will have to wait too long
With too many context switching:
- Takes too many resources and causes slowdown on overhead
Layout of process in memory
Stack
Heap
data
Text
Text
The actual executable code; fixed-size and read-only
Data
Global and static variables; Fixed-size - determined at compile time
Heap
Memory that is dynamically allocated during runtime; Size can shrink/grow
Stack
Temporary storage (function parameters, return addresses and local variables) ; Size shrinks/grows
Stack as a data structure
A LIFO (Last In First Out) data structure
Operations:
- Push: adding to the stack
- Pop: removing from the stack
Upon Function Call: Activation record (parameters, local variables, return address) pushed to stack
Upon Function Return: Activation record popped from stack
The Heap as a data structure
Dynamically allocated (grows or shrinks based on the needs of the process), the only similarity to a stack
Blocks of memory are allocated and removed in an arbitrary (any) order
Used when you need:
- To store a large block of memory for a longer period of time
- Variables that can change size dynamically
If allocated during runtime, it goes onto the heap
Process spawning:
The method by which a process (parent) creates a new process (child)
In Linux there are four system calls for process spawning
fork
exec
wait
exit
What is forking
Fork creates a child process with a unique process ID. The child is a copy of the parent process
Fork returns
* 0 to the child process
* the process ID of the child process to the parent process
Wait
parent process is put in waiting state until child process finishes
Exit
when done, the child process issues the exit system call, and the parent process can resume.