OS Chapter 5 Simple Notes - 075257
OS Chapter 5 Simple Notes - 075257
1. Process Characteristics
A process in an operating system is an instance of a program in execution. It has two main
characteristics:
What it means: A process is allocated its own virtual address space (where its code,
data, and stack reside) and control over resources like files and I/O devices.
Example: Think of a process as a container that holds a program's data, like the text file
you are working on in a word processor.
What it means: A process has an execution path. It can be broken down into several
threads (a smaller unit of execution), and the process can run concurrently with other
processes.
Example: While one process is running, another can be waiting for its turn, or some tasks
of the process can run at different times.
What it means: In a multithreaded environment, multiple threads run within the same
process. Each thread is like a mini process that runs concurrently but shares the same
resources (memory, file handles) as other threads in the same process.
Example: Web browsers use multithreading to load different parts of a webpage
simultaneously.
b) Single-threading:
1. 1:1 Model:
o What it means: Each thread is mapped to its own process. Each thread runs
independently, and the process provides resources to the threads.
o Example: Older versions of UNIX.
2. M:1 Model:
o What it means: Multiple threads are managed within a single process. The
threads share the resources of the process and can run concurrently within the
same address space.
o Example: Windows NT, Solaris.
3. 1:M Model:
o What it means: Threads can migrate across different processes or systems. A
thread may move between machines and address spaces.
o Example: Cloud-based systems like Ra.
4. M:M Model:
o What it means: A hybrid model where multiple threads are mapped to multiple
processes. Both user and kernel threads can be executed concurrently.
o Example: TRIX (a real-time OS).
Characteristics:
o Have a virtual address space (this is where the program code and data live).
o Have protected access to resources like files, processors, and other processes.
b) Threads:
Characteristics:
o Have an execution state (whether they’re running, ready, or blocked).
o Have an execution stack and static storage for local variables.
o Share the process’s address space and resources with other threads of the same
process.
Communication: Threads in the same process can communicate directly without
invoking the kernel (the core part of the OS that manages resources). This makes
communication faster and more efficient.
5. Thread Benefits over Processes
Threads offer several advantages over processes, including:
Imagine two threads, T1 and T2, working with the same variables: A, B, and C.
T1 calculates C = A + B.
T2 modifies A and B by transferring some amount X.
If T1 computes C after T2 has updated A but before T2 updates B, T1 will get an incorrect
result. This is an example of an inconsistent view, and it can happen without proper
synchronization.
8. Thread States
Threads can be in one of three key states:
Threads within the same process share the same address space, so if one thread is suspended,
the whole process gets suspended.
The kernel does not know about the threads. They are managed entirely by a user-level
library.
Thread switching happens without entering kernel mode, making it faster.
Advantages:
Inconveniences:
When a system call (like accessing a file) blocks a thread, the whole process gets
blocked, including all threads.
Threads cannot run on different processors simultaneously.
The kernel is responsible for managing threads, meaning it knows about each thread in
the system.
Thread switching requires the kernel to be involved.
Advantages:
Inconveniences:
Thread switching is slower because the kernel is involved in the process, which requires
switching between user mode and kernel mode.
1. Many-to-One:
o Multiple user-level threads are mapped to a single kernel thread.
o Common in systems that do not support kernel threads.
2. One-to-One:
o Each user-level thread corresponds to a kernel thread.
o Examples: Windows NT, OS/2.
3. Many-to-Many:
o Multiple user-level threads are mapped to multiple kernel threads.
o Allows the OS to create as many kernel threads as needed.
o Examples: Solaris, Windows NT/2000 with the ThreadFiber package.
In conclusion, threads allow for more efficient multitasking and resource usage compared to
processes, and different systems and models are used to manage these threads, depending on the
OS capabilities and requirements.
Process and Threads: