Proccess Management Flashcards
Define a program
A program is a set of instructions for performing a specific task (passive), and is stored on disk.
when you run it, it is a program associated with a process
What is a process
A process is a program in execution (active), and requires CPU resources, primary memory, and I/O.
By organising a computer system into processes we achieve what
both modularity (we can switch between them) and improved performance (allowing us to improve performance).
What happens in the NEW state of a process lifecycle?
The process is created and enters the system. It awaits admission to the READY state.
What happens in the READY state?
The process is prepared to run and waits to be dispatched to the CPU.
What happens in the RUNNING state?
The process is actively executing on the CPU.
When does a process move to the WAITING state?
A process moves to the WAITING state when it begins I/O operations and waits for I/O to complete.
When does a process enter the TERMINATED state?
The process enters the TERMINATED state when it finishes execution and exits.
What is the transition from READY to RUNNING called?
The transition is called dispatch, where the CPU scheduler selects a process to run.
What happens when a process is paused during execution?
The process transitions from RUNNING back to READY if it’s preempted (e.g., by a higher-priority process).
What happens when a process starts an I/O operation?
The process moves from RUNNING to WAITING.
What happens when a process completes its I/O operation?
The process transitions from WAITING to READY.
What determines the transfer between READY and RUNNING states?
The transfer depends on processor scheduling, which prioritises processes based on their assigned priority.
What is a process control block
A Process Control Block (PCB) is a data structure maintained by the operating system to store information about a process. It is used to manage processes during execution.
What are the components of the process control block
- Process number
- Process state
- process address space
- process I/O
Where is the process control block stored
in the memory or on the disk
How to stop running process A and start process B:
- change the process scheduling state of process A
- save the context of process A
- load the context of process B
- change the process scheduling state of process B
What is a context switch
when the CPU switches from running one process to another.
What is the tradeoff of context switches
Too few switches lead to poor responsiveness (as it is never actually running the task rather just moving data), while too many switches increase overhead, reducing efficiency.
What 4 sections does a process address space have
- a stack for temporary data
- a heap for dynamically-allocated data
- a data for static data
- a text for program code
How does a stack work
When a function is called, temporary variables are added to the top of the stack. When exiting a function, these variables are removed from the top of the stack.
How does a heap work
In the heap, blocks of memory are allocated and removed in an arbitrary order. The heap is used for variables that need to persist beyond the scope of a single function or need a flexible amount of memory.
What is the issue with stack and heap in address space
The stack grows downwards while the heap grows upwards thus they could collide so its up to the OS to stop this by providing more address space
What is process calling
A process is created at the request of a different process. In Linux there are four system calls for process spawning.
In process spawning, what is the relationship between a parent and child process?
The parent process creates a child process. The child process can execute the same code as the parent or replace its code with a new program using exec.
What system call is commonly used to create a new process in Linux?
The fork system call is commonly used to create a new process.
What happens when fork is called?
fork creates a child process that is a copy of the parent process, with its own process ID and address space.
What are the return values of fork?
The parent process receives the child’s process ID as the return value of fork.
The child process receives 0 as the return value.
How can a child process run a different program after fork?
The child process can replace its code with a new program using the exec system call.
What does the exec system call allow for
The exec system call allows a process to replace its current program with a new executable file.
What does the wait system call do
The wait system call causes the parent process to pause execution until the child process completes.
What does the exit system call do
The exit system call is issued by the child process when it finishes its task.
How may Interprocess communication be implemented
either using:
- shared memory
- or message passing
What is interprocess communication by shared memory
involves processes writing data to/reading data from from an agreed area of memory.
What is interprocess communication by message passing
involves processes sending messages to/receiving messages from an agreed mailbox.
Shared Memory vs message passing
Message passing requires regular system calls, while shared memory only requires system calls to set up the shared memory space. As a result, shared memory is generally more efficient for large data transfers, whereas message passing is better suited for smaller data exchanges.
When does a process move into the running state
When the schedueler decides to exeter the program it move to the running state.