Chp 2 Process/Threads Flashcards
How does the OS keep track of each process?
Process Control Block
Process
Program in execution
Instance of a program being executed by an OS
What is the concrete representation of a process?
PCB
Who creates the PCB for a process?
OS
Process Ready-> Running caused by
OS
Process Running -> blocked caused by
process
Process Running -> Ready caused by
OS
Process Blocked -> Ready caused by
Another process releasing the resources it was waiting for
How many processes is the cpu running at a time
1
Context switch
The transfer of control from one process to another
CPU state
Consists of all intermediate values held in any CPU registers and hardware flags at the time of interruption
3 parts of a process image
Executable program
Associated data needed by the program
Execution context
What is in execution context
ID, state, cpu registers, stack, etc.
What is PCB
A snapshot that contains all necessary and sufficient data to restart a process where it left off
Where (broad) is the PCB?
In the context
Where is the PCB?
One entry in the OSs process table (array or linked list)
What are two parts of process (broad)
User address space, context
What does user address space contain?
Program, dataW
What does context contain
Stack, PCB
4 ways a process can be created
System Boots
User requests to run an application
An existing process spawns a child process
A batch system takes on the next job in line
3 ways a process can be terminated
Regular completion
Fatal Error
Killed by another process via the kernel
2 events that lead to process pause/dispatch
I/O Wait - OS triggered
Preemptive timeout - Hardware Interrupt triggered
When the CPU switches to another process (context switch) what two things must it do?
The system must save the state of the old process
The system must load the saved state for the new process
Does the system do useful work during context switching
no
What events trigger the OS to switch processes?
Interrupts: External, Asynchronous
Executions (traps): Internal, synchronous (but involuntary)
System calls (traps): Voluntary synchronous events after calling a specific OS service
Long term scheduler
Decides to add a program to the pool of processes to be executed (job scheduling)
Medium term scheduler
The decision to add to the number of processes that are partially or fully in main memory (swapping)
Short term scheduling
CPU scheduling, decides as to which available processes in memory are to be executed by the processor
Which scheduler controls the degree of multiprogamming
Long term scheduler
I/O bound process
spends more time in I/O than computations, many short CPU bursts
CPU-bound process
Spends more time doing computations, few very long CPU bursts
Which scheduler removes processes from memory “temporarily” to reduce degree of multiprogramming?
Medium term scheduler
Cooperating processes
Can affect or be affected by the execution of another process
Two mechanisms for interprocess communication
Shared Memory
Message Passing
What do P and Q need to establish if they want to communicate?
Communication Link
Direct Communication
Processes must name each other explicitly
Indirect Communication
Messages are directed and received from mailboxes (ports)
Solutions to multiple processes on a mailbox
Allow a link to be associated with at most two processes
Allow only one process at a time to execute a “receive” operation
Allow the system to select the receiver arbitrarily, sender is notified who the receiver was
Blocking message passing
Synchronous, sender blocks until message is received, receiver blocks until message is available
Non-blocking message passing
Asynchronous, sender sends message and continues, receiver receives valid message or null
Buffering
Queue of messages attached to the link
Buffering 3 implementations
zero capacity
Bounded capacity - finite
unbounded capacity - infinite
When timesharing is happening, what is each process essentially given?
A virtual CPU
What are two ways that OS organize all PCBs?
Array of structures: wasted memory space
Array of pointers to dynamically allocated PCBs: overhead of dynamic memory management
Waiting list
Contains all processes blocked on a resource because the resource is not available
Ready List
List containing all processes that are in the ready state and thus are able to run on the CPU
When a process gets destroyed what happens to its PCB
Frees PCB data structure and removes any references to the PCB from the system
Resource Control Block
Data structure that represents a resource
Allocated Resource
A process has access to and is able to utilize the resource
Free resource
when it may be allocated to a requesting process
Can a process be blocked on more than one resource?
No
Scheduler Function
Determines which process should run next and starts the process
Concurrent Programming
Running several tasks at the same time
In theory, dividing a program into n smaller parts and running on n processes results in
n time speedup
Execution of concurrent tasks on single processor
Multithreaded programming
Execution of concurrent tasks on several processor in close proximity
Parallel Computing
Execution of concurrent tasks on several processors distributed across a network
Distributed computing
3 positives of using a single process with multiple threads
Faster
Less overhead for creation, switching, termination
Share same address space
Multithreading
The execution part is a “thread” that can be multiplied
Each thread of execution receives its own
Control block and stack, which includes own execution state, copy of cpu registers, execution history(stack)
Process identification data is per
process
thread identifiers is per
thread
CPU state information is per
thread
process control information– scheduling is per
thread
Process control information, used memory and i/o, opened files, pointer to next pcb, is per
process
Process Spawning
Setting up PCB
Allocation of address space
Loading the program into the allocated address space
Passing on the PCB to the scheduler
Threads are created _ processes, and _ to processes
within, belong
All threads created within one process, _ the resources of the process _ the address space
Share, include
Advantages of threads 3
Much quicker to create than a process
Much quicker to switch between threads than to switch between processes
Threads share data easily
Disadvantages of thread
Processes are more flexible (dont have to run on same processor
No security between threads
If one thread blocks, all threads block on user thread package
Thread Pools
Since unlimited threads will exhaust system resources, create a number of threads at process startup and put them in a pool where they await work
User-level thread implementation
- kernel
- pros
-cons
The kernel is not aware of the existence of threads, it only processes with one thread of execution
Each user process manages its own private thread table
Pros: Light thread switching (no kernel mode privileges), cross platform
Cons: If a thread blocks, the entire process is blocked, including all other threads in it
Kernel-level thread implementation
-kernel
-pros
-cons
The kernel knows about and manages the threads: creating and destroying threads are system calls
pros: find grain scheduling, done on a thread basis. If one thread blocks then it can pick another thread
Cons: Heavy thread switching involving mode switch
Many to one multithread model
Several user-level threads mapped to a single kernel thread
drawback: one blocks then all blocks, only one thread can access the kernel at a time
One to One multithreading model
Each user-level thread maps to a kernel thread
drawback: need to create many threads
many to many multithreading model
Allows many user level threads to be mapped to a smaller number of kernel threads
Allows OS to create a sufficient number of kernel threads
Hybrid multithreading model
Similar to many to many, but allows a user thread to be bound to a kernel thread
Asynchronous thread cancellation
Terminates the target thread immediately
Deferred cancellation
Allows the target thread to periodically check if it should be cancelled ( more controlled and safe)