Process management Flashcards
Define the term “process” in the context of operating systems
A process is a program in execution. It’s not just the code itself but includes the program’s current state and resources.
Distinguish between a “program” and a “process.”
○
A program consists of executable code and is typically stored as a file on disk.
○
A process is that program actively running in memory. It includes the code, data, and system resources the program is using.
What are the fundamental Linux primitives (system calls) used in process creation and management?
○ fork(): Creates a new process that is an identical copy of the parent process. Returns the child’s process ID (PID) to the parent and 0 to the child.
○ exec(filename): Replaces the current process’s code with the code from the specified file (the program to be executed).
○ wait(): Causes the parent process to pause execution until a child process terminates.
○ exit(): Terminates the calling process.
What constitutes a process’s state? In other words, what are the essential elements that define a process?
○ Registers: Hold temporary data and the program counter.
○ Address Space: Contains the code, data (heap, stack), and libraries the process can access.
○ Open Files: A list of files the process has open.
Describe the components and organization of a process’s address space.
○
Code: The program instructions.
○
Static Data: Global variables with fixed sizes.
○
Heap: Dynamically allocated memory during program execution.
○
Stack: Used for function calls, local variables, and function parameters.
Compare and contrast stack-based and heap-based dynamic memory allocation.
○ Stack:
■ Memory allocation and deallocation are fast.
■ Follows a Last-In, First-Out (LIFO) order, simplifying memory management.
■ Used for function call frames (local variables, parameters).
■ Managed automatically.
○ Heap:
■ Allocation can be slower due to searching for free space.
■ Flexible allocation and deallocation order.
■ Can lead to fragmentation (unused memory between allocated blocks).
■ Programmers are responsible for allocating (using malloc()) and deallocating (using free()) memory.
How does an operating system uniquely identify each process?
Every process is assigned a unique Process Identifier (PID), a unique numerical ID.
What is the purpose of a Process Control Block (PCB)?
○ The PCB is a data structure the operating system uses to store information about a process.
○ This information includes the PID, process state, register values (save area for context switching), and other relevant details.
Explain the concept of a “process tree” in Linux.
○ The process tree is a hierarchical representation of processes on a Linux system.
○ The init process is the root of the tree, created during system boot.
○ When a process (parent) creates a new process (child) using fork(), the child becomes a node below the parent in the tree.
Why use the combination of fork() and exec() instead of a single system call to create and run a new program?
○ Environment Inheritance: fork() allows the child process to inherit a copy of the parent’s environment (open files, environment variables).
○ Flexibility: The parent can modify the child’s environment after fork() and before exec(), giving fine-grained control over the new program’s execution context.
What are the primary drawbacks of a single-process computing system?
○ Long Wait Times: Users experience significant delays because only one program can run at a time, and they must wait for it to finish.
○ Low Utilization: CPU resources are wasted during I/O operations. When a process is waiting for I/O, the CPU sits idle instead of doing useful work.
What are the key advantages of a multiprocess system compared to a single-process system?
○ Improved CPU Utilization: While one process waits for I/O, another process can use the CPU. This leads to more efficient hardware resource usage.
○ Reduced Wait Times: Multiple processes running concurrently give the illusion of simultaneous execution, reducing user wait times for task completion.
List and briefly describe the typical states a process can be in within an operating system.
○ Running: The process is currently executing instructions on the CPU.
○ Ready: The process is runnable (ready to use the CPU) but is waiting for its turn to be scheduled.
○ Waiting (Blocked): The process is waiting for an event (like I/O completion) before it can proceed.
○ New: The process is being created.
○ Terminated: The process has finished executing or has been terminated.
What is a process switch, and why is it necessary in a multiprocess system?
○ A process switch is the procedure of suspending the execution of one process on the CPU and resuming (or starting) the execution of another process.
○ It’s how the OS gives the illusion of concurrency, allowing multiple processes to share the CPU.
Describe the steps involved in a context switch.
1.Save the Context of the Running Process: Store the values of the CPU registers, program counter, and other relevant information of the process that is currently running into its PCB.
2.Load the Context of the Next Process: Retrieve the saved context of the process that is going to run next from its PCB and load it into the CPU registers.