CS 134

Key Points: Resource Management in Operating Systems

Resource Identifiers

  1. Definition: Ways for user programs to refer to resources managed by the operating system.
  2. Approaches:
    • Numeric identifiers (e.g., array indices)
    • Tagged indexes (combining an index with a generation number)
    • Hash tables
  3. Properties: Easy to validate; typically small integers for human readability
  4. Examples: File descriptors, Process IDs (PIDs)

File Descriptors

  1. Definition: Small non-negative integers referring to open files or I/O streams.
  2. Properties:
    • Process-local (not shared between processes, except after fork)
    • Have an associated file offset for regular files
    • Can be duplicated (dup/dup2)
  3. Behavior:
    • Shared file offset between duplicated file descriptors
    • Inheritance across fork

Process IDs (PIDs)

  1. Definition: Unique identifiers for processes in the system.
  2. Properties:
    • Typically small integers for human readability
    • System-wide (unlike file descriptors)
    • Reused over time, but not immediately
  3. Implementation: Often uses tagged indexes to prevent rapid PID reuse.

Key System Calls

  1. 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)
  2. _exit:
    • Terminates the calling process
    • Resources released, but process-table entry kept until parent calls waitpid
  3. 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
  4. 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

  1. Resource Tables: Often implemented as fixed-size arrays or hash tables in the kernel.
  2. Memory Management: Careful consideration needed when copying data between user and kernel space.
  3. Zombie Processes: Processes that have exited but whose parents haven't yet called waitpid.
  4. 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, and waitpid involves 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.)