CS 134

Key Points: Processes and Threads

Processes

  1. Definition: An abstraction representing a running program on the system.
  2. Visualization: Process hierarchies can be complex, with many processes running even on seemingly idle systems.
  3. Lifecycle: Processes go through various states (New, Ready, Running, Waiting, Terminated).
  4. Abstraction: Processes are an abstraction created by the operating system, not inherently “real” entities.

Process Attributes

  1. Memory Space: Includes program code, data, and stack.
  2. Execution State: CPU registers, program counter, stack pointer.
  3. I/O State: File descriptors, working directory, root directory.
  4. Scheduling Information: Process state, priority, scheduling class.
  5. Process Information: PID, PPID, start time, CPU time used.
  6. Security Information: User ID, Group ID, access rights.

Threads

  1. Definition: A lightweight way to run multiple tasks concurrently within the same program.
  2. Green Threads (User-Space Threads):
    • Implemented entirely in user space.
    • Lightweight but can't take advantage of multicore systems.
    • Examples: Early versions of Java, Python's greenlet.
  3. Native Threads:
    • Supported by the operating system kernel.
    • Can utilize multiple cores but are heavier than green threads.
  4. Retrofitting Threads: Adding thread support to existing OSes required revisiting many design decisions.

Threading Challenges

  1. Per-process vs. Per-thread Attributes: Deciding which attributes should be shared or separate.
  2. Signal Handling: Complexity in handling signals in multithreaded environments.
  3. Fork in Multithreaded Programs: Challenges in implementing fork() with multiple threads.

Hybrid Approaches

  1. Synchronization in User Space: Improving efficiency by handling some synchronization without kernel involvement.
  2. N:M Threading: Mapping N user-space threads to M kernel-supported threads.
  3. Examples: Go's goroutines, Apple's Grand Central Dispatch, Windows Thread Pool API.

Remember

  • Processes are a fundamental abstraction in operating systems, representing running programs.
  • Threads provide a way to have multiple execution streams within a single process.
  • There are trade-offs between user-space (green) threads and kernel-supported (native) threads.
  • Adding thread support to existing operating systems involved complex design decisions.
  • Modern systems often use hybrid approaches to balance efficiency and functionality in threading.
  • Understanding the distinctions and relationships between processes and threads is crucial for effective system design and programming.

(When logged in, completion status appears here.)