Operating System Threads Process and Kernels What is

  • Slides: 30
Download presentation
Operating System Threads, Process and Kernels

Operating System Threads, Process and Kernels

What is Process? �A process can be thought of as a program in execution.

What is Process? �A process can be thought of as a program in execution. �It needs certain resources to execute. �Contains only a single threads (primitive). �The OS is responsible to run a process. � Deletion and creation of process � Scheduling of Process � Deadlock handling for a process

Characteristics of a Process �Early computers system doesn’t allow multiple programs to be executed

Characteristics of a Process �Early computers system doesn’t allow multiple programs to be executed at a time. �Nowadays, computers allows multiple process too be executed at a time.

The Process State �New: The process is being created. �Running: Instructions are being executed.

The Process State �New: The process is being created. �Running: Instructions are being executed. �Waiting: The process is waiting for some event to occur. �Ready: The process is waiting to be assigned to a processor. �Terminated: The process has finished execution.

The Process State Diagram

The Process State Diagram

Process Control Block �A Process Control Block (PCB, also called Task Control Block or

Process Control Block �A Process Control Block (PCB, also called Task Control Block or Task Struct) is a data structure in the operating system kernel containing the information needed to manage a particular process.

Context Switch �It is the process of giving each process a fair share of

Context Switch �It is the process of giving each process a fair share of CPU time. �It switches the CPU to execute another process. How is it done? 1. a hardware clock generates interrupts periodically 2. by means of saving the old state of a process and loading the saved state for the new process.

What is a Kernel? It can be thought of as the bridge between applications

What is a Kernel? It can be thought of as the bridge between applications and the actual data processing done at the hardware level.

Basic Facilities of Kernel 1. Process Management - The main task of a kernel

Basic Facilities of Kernel 1. Process Management - The main task of a kernel is to allow the execution of applications and support them with features such as hardware abstractions. Hardware abstractions are sets of routines in software that emulate some platform-specific details, giving programs direct access to the hardware resources.

2. Memory management - The kernel has full access to the system's memory and

2. Memory management - The kernel has full access to the system's memory and must allow processes to safely access this memory as they require it.

3. Device management - To perform useful functions, processes needs an access to the

3. Device management - To perform useful functions, processes needs an access to the peripherals connected to the computer, which are controlled by the kernel through device manager.

4. System calls - To actually perform useful work, a process must be able

4. System calls - To actually perform useful work, a process must be able to access the services provided by the kernel.

What are Threads? �Sometimes called as lightweight process embedded on the OS itself or

What are Threads? �Sometimes called as lightweight process embedded on the OS itself or in the application. What are Multi-threads? It refers to the ability of an operating system to support multiple threads of execution within a single process.

Motivation A process without “Threads” Consider this example: 1. Execution of a running process

Motivation A process without “Threads” Consider this example: 1. Execution of a running process e. g. , a word processor. Conflict: One thread per process… Solution: Multiple thread per process…

Example of Applications with Multithreaded Technology �A Web Browser �A Word Processor �A Web

Example of Applications with Multithreaded Technology �A Web Browser �A Word Processor �A Web Server (accepts clients with several tasks)

Benefits 1. Responsiveness 2. Resource Sharing 3. Economy

Benefits 1. Responsiveness 2. Resource Sharing 3. Economy

Multithreading Models � 1. Many-to-one model

Multithreading Models � 1. Many-to-one model

2. One-to-one model

2. One-to-one model

3. Many-to-many model

3. Many-to-many model

Concepts of Threads �The implementation of threads and processes differs from one OS to

Concepts of Threads �The implementation of threads and processes differs from one OS to another, but in most cases, a thread is contained inside a process. �Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources.

Threads compared with processes Threads differ from traditional multitasking operating system processes in that:

Threads compared with processes Threads differ from traditional multitasking operating system processes in that: �processes are typically independent, while threads exist as subsets of a process. �processes have separate address space, whereas threads share their address space. �Context switching between threads in the same process is typically faster than context switching between processes.

Advantage of Multithreading Technology �If a thread gets a lot of cache misses, the

Advantage of Multithreading Technology �If a thread gets a lot of cache misses, the other thread(s) can continue �If a thread can not use all the computing resources of the running thread, another thread permits not to leave these idle. �If several threads work on the same set of data, they can actually share their cache.

Disadvantage of Multithreading Technology �Multiple threads can interfere with each. �Execution times of multiple

Disadvantage of Multithreading Technology �Multiple threads can interfere with each. �Execution times of multiple threads are not improved but can be degraded (servers). �Hardware support for Multithreading is more visible to software.

Single and Multithreaded Process Model

Single and Multithreaded Process Model

Another example application of thread technology �A File Server on a LAN 1. It

Another example application of thread technology �A File Server on a LAN 1. It needs to handle several file requests over a short period. 2. Hence more efficient to create (and destroy) a single thread for each request. 3. Multiple threads can possibly be executing simultaneously on different processors.

�Matrix Multiplication - essentially involves taking the rows of one matrix and multiplying and

�Matrix Multiplication - essentially involves taking the rows of one matrix and multiplying and adding corresponding columns in a second matrix

Thread Level There are two (2) broad categories of thread implementation: 1. User-Level Threads

Thread Level There are two (2) broad categories of thread implementation: 1. User-Level Threads -- Thread Libraries. 2. Kernel-level Threads -- System Calls.

ULT In this level, the kernel is not aware of the existence of threads.

ULT In this level, the kernel is not aware of the existence of threads. 2. All thread management is done by the application by using a thread library. 3. Scheduling can be application specific -- choose the best algorithm. 4. ULTs can run on any OS -- Only needs a thread library. 1.

KLT In this level, All thread management is done by kernel. 2. No thread

KLT In this level, All thread management is done by kernel. 2. No thread library but an API (system calls) to the kernel thread facility exists. 3. The kernel maintains context information for the process and the threads, switching between threads requires the kernel Scheduling is performed on a thread basis. 4. kernel routines can be multithreaded. 1.