Key Points: Resource Management in Operating Systems
Resource Identifiers
- Definition: Ways for user programs to refer to resources managed by the operating system.
- Approaches:
- Numeric identifiers (e.g., array indices)
- Tagged indexes (combining an index with a generation number)
- Hash tables
- Properties: Easy to validate; typically small integers for human readability
- Examples: File descriptors, Process IDs (PIDs)
File Descriptors
- Definition: Small non-negative integers referring to open files or I/O streams.
- Properties:
- Process-local (not shared between processes, except after
fork) - Have an associated file offset for regular files
- Can be duplicated (
dup/dup2)
- Process-local (not shared between processes, except after
- Behavior:
- Shared file offset between duplicated file descriptors
- Inheritance across
fork
Process IDs (PIDs)
- Definition: Unique identifiers for processes in the system.
- Properties:
- Typically small integers for human readability
- System-wide (unlike file descriptors)
- Reused over time, but not immediately
- Implementation: Often uses tagged indexes to prevent rapid PID reuse.
Key System Calls
fork:- Creates a new process as an exact copy of the calling process
- Child process gets a new PID
- File descriptors are duplicated (shared underlying open file objects)
_exit:- Terminates the calling process
- Resources released, but process-table entry kept until parent calls
waitpid
waitpid:- Waits for a child process to exit
- Retrieves the child's exit status
- Allows the system to fully remove the child's process-table entry
execv:- Replaces the current process with a new program
- Challenges include argument passing between address spaces
- Often has a limit on total argument size (
ARG_MAX)
Implementation Considerations
- Resource Tables: Often implemented as fixed-size arrays or hash tables in the kernel.
- Memory Management: Careful consideration needed when copying data between user and kernel space.
- Zombie Processes: Processes that have exited but whose parents haven't yet called
waitpid. - Orphan Processes: Processes whose parent has exited before they have.
Remember
- Understanding resource identifiers is crucial for system-call implementation and usage.
- File descriptors and PIDs have different scopes and behaviors.
- Implementing system calls such as
fork,exec, andwaitpidinvolves complex resource management. - Careful design is needed to handle edge cases such as zombie and orphan processes.
- There are often trade-offs between simplicity, efficiency, and robustness in OS design.
(When logged in, completion status appears here.)