Heavyweight processes &Threads Flashcards
what are the 2 Process Types?
Heavyweight:
- The standard notion of a process when you start a program
Thread:
- Concurrency within a single “program”
What are Heavyweight Processes?
Processes are independent of one another:
- Private address space
- Private OS resources
- Private PCB
- Scheduled on it’s own by the OS
Managed directly by the OS
What are threads?
- A set of related threads live within one heavyweight process
Within one heavyweight processes, the threads:
- Share address space, PCB, resources (like the open file table)
- Are scheduled together as the heavyweight process
- Share the interrupt vector
- Only have the basic hardware state as private components (instrction register, registers, condition code register, stack)
Often managed in user-space (context switches are faster)
Why have multiple types of processes?
- Different context switch times - Availability of resources - Dedicated OS resources - Effect on CPU scheduling - I/O blocking behaviour - Types of communication - Protection of the processes
What happens when we run the fork() command on a process P?
- fork() creates a copy (child) C of process P. C is then treated as independent of its parent process and allowed to execute whatever it must. All child processes created from P must be joined with it at the end of their run.
Give two examples of heavyweight process management.
- System Start-up
- Shells
- How do we typically create a thread?
- Where are threads created and managed? Do we use commands or function calls to manage them?
- Why must threads be run from the same executable?
- Threads are typically created within the userspace of the program. They require the inclusion of external libraries - such as pthreads.h - to work.
- Threads are created and managed within the userspace of the heavyweight process containing them. We manage them with function calls, such as pthread_create() and pthread_join().
- Threads are run from the same executable because there is only one primary executable within each heavyweight process, which itself must be the host to all threads within it.
What can separate processes do?
- Act independently
- Do serial multitasking (hand off control between the 2 processes in a pre-determined way)
Cooperate:
- one process can affect the other
- Process execution is not pre-determined
- Requires communication and synchronization
Why have cooperating processes?
Cooperating processes result in improved responsiveness and resource sharing between them. The operating system is thus taxed less, creating a more efficient system.
What are the three methods of interprocess communication?
Processes can communicate via:
- Files
- Shared Memory
- Named Systems
Why is it atypical for processes to communicate via files?
Communication via files is a clumsy method of communication: It consumes many resources and assumes a shared-file system. This is an inefficient method of communicating, and rarely done.
Which type of process typically communicates through shared memory? What are some pros and cons to shared memory communication?
Communication via shared memory is typically done with threads. In general, this is a fast method of communication which is bi-directional (i.e. allows back-and-forth communication). However, this creates problems with mutual exclusion, atomicity, and execution of critical sections.
What are two types of communication via named systems? List three traits of one of these types.
Two types: Direct and Indirect.
Direct traits:
- Can identify the peer process through address, PID, and OS construct.
- Changing PID could damage or corrupt the process.
- Data from one process is sent to a specific peer process
- Communication can be:
- –symmetric - where the sender and receiver must name each other for the communication to succeed, OR
- –asymmetric - where only the sender needs to name the receiver for the communication to succeed.
Message Passing Issues
- Peer disappears
- Messages are lost
- Messages are scrambled
- Messages arrive out of order
Risk:
- Shared memory - low probability of these issues
- On a shared computer - peer may disappear but the rest are improbable
- across a network - anything can happen
Buffering:
- None
- bounded
- unbounded
Method of transmission:
- Pass by copy
- pass by reference
Message Size:
- Fixed size
- variable size
Mapping threads to kernel threads.
- A kernel thread is the basic unit of scheduling and process management seen by the kernel
- Traditionally, one heavyweight process matches one kernel thread