Core Distinction
Which of the following best describes the primary difference between a process and a thread?
- A process has its own memory space, while threads within the same process share memory.
- Threads always execute on different CPUs, while processes run on the same CPU.
- Processes can only run one at a time, while multiple threads can run in parallel.
- Threads cannot communicate with each other, but processes can.
- A process is just a lightweight version of a thread.
Thread Communication
Which mechanism do threads within the same process commonly use to share data?
- Shared variables
- File system
- Socket communication
- Remote procedure calls
- DNS lookup
OS Resource Handling
What is one key resource difference between processes and threads in terms of OS management?
- Threads share most OS resources with their parent process, while processes have separate resources.
- Processes do not consume any CPU time, while threads do.
- Threads have their own independent file descriptors, while processes do not.
- Threads must have a separate virtual memory, while processes share virtual memory.
- Both processes and threads always share registers.
Scenario: Web Server
A web server wants to handle multiple client requests simultaneously but efficiently shares data and cache between workers. Which would be preferable?
- Use multiple threads within a single process.
- Run one process for each client, no threads.
- Fork a new process without any shared cache.
- Use stateless client-only operations.
- Spawn a new virtual machine per request.
Interprocess Communication (IPC)
Which of the following is a common method for processes to communicate with each other?
- Pipes
- Global variables
- Direct function call
- Register swapping
- Thread forking
Concurrency Overhead
What is a significant overhead when creating a new process compared to creating a new thread?
- Allocating separate memory space for the process
- Failing to initialize a stack pointer
- Copying the OS kernel code
- Resetting user permissions each time
- Assigning the same process ID to multiple instances
Thread Safety
In a multithreaded program, which issue is most likely to occur if shared data is not properly protected?
- Race condition
- Dead socket
- Stack underrun
- Page thrashing
- Kernel panic typo
Python Example
Given the following Python snippet, what is being created: 'threading.Thread(target=my_func).start()'?
- A new thread
- A new process
- A socket connection
- A timer event
- A global semaphore
Thread vs. Process Isolation
Why are processes considered more secure in terms of fault isolation compared to threads?
- Crashing one process does not directly affect others due to separate memory space.
- Processes always have higher priority in the OS scheduler.
- Threads are always blocked if any thread dies.
- Processes can only execute kernel code, making them safer.
- Threads cannot be paused by the OS.
Use Case: Video Encoding
A video encoding application needs to process several videos independently at the same time, with minimal data sharing. Which parallelism model is most appropriate?
- Launch each encoding job as a separate process.
- Create threads that all write to the same video file.
- Run all jobs in a single thread with time slicing.
- Spawn threads within a single process for all jobs.
- Share the same memory-mapped file between threads and processes.