Key Points: Processes and Threads
Processes
- Definition: An abstraction representing a running program on the system.
- Visualization: Process hierarchies can be complex, with many processes running even on seemingly idle systems.
- Lifecycle: Processes go through various states (New, Ready, Running, Waiting, Terminated).
- Abstraction: Processes are an abstraction created by the operating system, not inherently “real” entities.
Process Attributes
- Memory Space: Includes program code, data, and stack.
- Execution State: CPU registers, program counter, stack pointer.
- I/O State: File descriptors, working directory, root directory.
- Scheduling Information: Process state, priority, scheduling class.
- Process Information: PID, PPID, start time, CPU time used.
- Security Information: User ID, Group ID, access rights.
Threads
- Definition: A lightweight way to run multiple tasks concurrently within the same program.
- 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.
- Native Threads:
- Supported by the operating system kernel.
- Can utilize multiple cores but are heavier than green threads.
- Retrofitting Threads: Adding thread support to existing OSes required revisiting many design decisions.
Threading Challenges
- Per-process vs. Per-thread Attributes: Deciding which attributes should be shared or separate.
- Signal Handling: Complexity in handling signals in multithreaded environments.
- Fork in Multithreaded Programs: Challenges in implementing
fork()with multiple threads.
Hybrid Approaches
- Synchronization in User Space: Improving efficiency by handling some synchronization without kernel involvement.
- N:M Threading: Mapping N user-space threads to M kernel-supported threads.
- 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.)