1.3 Processes and Threads Flashcards
What is a Process?
- A running instance of a program
- Code written in program, that is being executed
How are multiple Processes Managed?
Process Control block is essential for managing multiple processes and allows for pause and resume
What is the Process Control Block?
A data structure stored in main memory
Collects all information about Process:
* Process ID
* Register Contents
* Memory space
* Asociated User or open Files
What is there are more processes then CPU cores?
- It uses Multitasking and Multiprocessing techniques to manage multiple processes
- OS switches between processes allowing each to execute each time slice
- This is achieved by storing program counter in Process control block
- Pause/resume
Multitasking vs. Multiprocessing
Multitasking
* Several processes in the system are executed quasi-parallel (also called “interleaved” or “concurrent”) by constantly changing the process being executed on one CPU.
Multiprocessing
* If there is more than one CPU or multiple cores in a system, multitasking is extended to multiprocessing, which enables true parallel processing.
Polling
Actively waiting by continuously querying the status of an I/O operation is called polling. The disadvantage of this approach is that the CPU is busy waiting and therefore unavailable for other processes.
What are process states?
- Can be found in entry of Process Control Block
Active
* Currently Processed by CPU
Ready
* Ready to be executed as soon as CPU available
Waiting
* Process cannot continue
* Lacks Data/wait for resources
* Requests via system calls
What is Preemptive Multitasking?
Allows the CPU to take control von currently running non-cooperactive processes
* Processes that naever make system calls
How does Preemptive Multitasking work?
- Hardware Alarm Clock sets maximum time slices before process begins
- Interrupt Handling once time slice expires
- Process switching, OS takes control
What is a Thread?
- Smallest Sequence of programmed instructions
- Subset of a programm
What is Thread Programming?
Special application programming interfaces (APIs) (e.g., the POSIX thread API, Windows thread API, Java threads) program threads of execution, which comprise a sequence of instructions within a process. After each sequence, a thread change can take place.
How to threads enable parrallel processing?
By concurrent execution of functions
What types of Threads are there?
User Level Threads
* Implemented at application level
* Without Kernel Intervention
Kernel Level Threads
* Recognized and managed by OS directly
* Can run on different processors
* Resource Intensive
Hardware Level Threads
* Allows single CPU to execute multiple threads simultaneously
* Hyper threding
Q2: Explain with examples the difference between user-level threads and kernel-level threads.
User-level threads and kernel-level threads are two types of threads that exist.
User-level threads are created and managed without kernel intervention, making them more light-weight and better for fine-grained control. However, because the operating system is not aware of their existence, if a user-level thread gets blocked on I/O then all threads within the process are blocked. An example could be a chatting program, where you would want to handle input and output independent of each other.
Kernel-level threads, on the other hand, are directly managed by the operating system, making them slower to create and manage, but also more robust. They are scheduled by the operating system, and have more system privileges than user-level threads. An example could be a large data-processing program that carries out several tasks, and each task would not want to be impacted by other tasks.