Processes & Threads Introduction to Operating Systems: Module 5.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Chapter 5 Threads os5.
Operating Systems Parallel Systems (Now basic OS knowledge)
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
Chapter 5 Processes and Threads Copyright © 2008.
Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
CS238 Lecture 5 Threads Dr. Alan R. Davis. Threads Definitions Benefits User and Kernel Threads Multithreading Models Solaris 2 Threads Java Threads.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
Process Concept n An operating system executes a variety of programs: –Batch system – jobs –Time-shared systems – user programs or tasks n Textbook uses.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
1 When to Switch Processes 3 triggers –System call, Interrupt and Trap System call –when a user program invokes a system call. e.g., a system call that.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
UNIX Process Creation Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique.
Operating System Concepts
Process Concept An operating system executes a variety of programs
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Process Description and Control A process is sometimes called a task, it is a program in execution.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Silberschatz and Galvin  Operating System Concepts Module 4: Processes Process Concept Process Scheduling Operation on Processes Cooperating.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Operating Systems Chapter 2
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Dr. T. Doom 4.1 CEG 433/633 - Operating Systems I Chapter 4: Processes What is a process? –Informally: A program in execution  Analogies: A script Vs.
Computer Studies (AL) Operating System Process Management - Process.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Department of Computer Science and Software Engineering
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
1 OS Review Processes and Threads Chi Zhang
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
Processes 2 Introduction to Operating Systems: Module 4.
Operating System Concepts
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process concept.
CS 6560: Operating Systems Design
Process Management Presented By Aditya Gupta Assistant Professor
Threads & multithreading
Operating System Concepts
Chapter 4: Threads.
ICS 143 Principles of Operating Systems
Process & its States Lecture 5.
Threads Chapter 4.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Presentation transcript:

Processes & Threads Introduction to Operating Systems: Module 5

CPU scheduling queue Enqueuer Ready Queue Dispatcher Context Switcher Ready Process PCBs CPU Remove the Running Process From Other States

Schedulers u Short-term scheduler (STS)  Selects a process from ready queue and give it CPU (dispatch)  Determine if the running process should be preempted (preempt) u Medium-term scheduler (MTS)  When needed, chooses ready processes to be saved to disk (suspend), or restored from disk (activate) u Long-term scheduler (LTS)  Initiates process (activate) u LTS and MTS determine the degree of multiprogramming  Processes may be either I/O-bound or CPU-bound  want to keep a good mix of each type of process to maximize resource utilization

join Process queues ready queue cpu I/O queuei/oI/O request time slice expires fork a child resource request resource queue condition queue child executes terminated

Queues as linked lists of PCBs Running Ready Disk1 Disk2 Printer

Process switching u Switching from one process to another u Often tens of microseconds (must be fast!) u Increases utilization of CPU  I/O and processing in parallel u incurs minimal overhead u CPU may have a process switch instruction

Process switching u A process switch may occur whenever the OS is invoked  system call  explicit request by the program, such as open file  the process may be blocked If so, OS will dispatch a new process  Trap (non-system call)  an error resulted from the last instruction may cause the process to be moved to the terminate state  Interrupt  the cause is external to the execution of the current instruction  control is transferred to the exception handler  After servicing the exception, a new process may be dispatched

Process switching interrupts u Clock  process uses all of its time slice  the exception handler will preempt the process u I/O  an I/O device has completed a transfer  wakeup processes waiting for this event and resume interrupted process, or  preempt interrupted process and dispatch a ready process with higher priority

Mode switching u Not all interrupts entail process switching  control can just return to the interrupted program  only processor state information needs to be saved u This is called mode switching  move from user mode to protected mode u Less overhead than process switching  no need to update PCB

u Stop the current process (process A)  Save enough state information (or context ) so that process A can be restarted later u Select a ready process (process B) u Load B’s state  memory mapping info, program counter, general registers, open file table (pointer), etc. u (Re)start B Process switching steps

Threads u A sequential execution stream within a process  sometimes called a lightweight process (LWP) u The major advantages of threads  low cost of thread switching  easy mechanism for shared resources  easily take advantage of multiprocessor system u The major disadvantages  harder to debug  unneeded overhead if threads aren’t used

Threads u Threads within a process (or task) share  text segment  data segment  OS resources (open files and signals) u Each thread has its own  program counter  register set  stack space

A Process (kernel view) Kernel Support Program Text Data Process Status Resources Allocate resources to processes when they are needed

A task and its family of threads Program Text Process Status Global data Thread Status Stack Thread Resources Task (Process) Program counters

Why threads become popular now? u SMPs (Symmetric Multiprocessors)  2 to 128 processors sharing  System bus  I/O system  Main memory  One operating system for all processors

Three types of thread systems u Kernel-supported threads (Mach, OS/2, NT) u User-level threads; supported above the kernel, via a set of library calls at the user level u Hybrid approach implements both user-level and kernel-supported threads (Solaris)

A simple view Thread 0 Thread 1 Thread 3 Thread 2 Thread run time libraries Kernel (see process) User-level Kernel (see thread) Kernel-level System call A User Program Thread 0 Thread 1 Thread 3 Thread 2

Kernel-level versus User-level threads u User-level thread  User-level activities; no kernel involvement  Basic scheduling unit in OS is process  Threads of the same process can not run on different CPUs in SMP in parallel u Kernel-level thread  Each process consists of several threads  Basic scheduling unit is thread  Can run on different CPUs in SMP in parallel

Advantages of kernel threads u Higher application throughput  if there were no kernel thread support  need I/O means the process goes into waiting state and wait until the I/O is complete  with multiple kernel threads per task  Block the I/O requesting thread and continue to work on another thread  Increases the overall throughput of the application

Advantages of user level threads u Threads are cheap  can be implemented at user levels, no kernel resources u Threads are fast  no system calls, switching modes involved

Using Threads - Windowing System Window Threads Application Minimized thread switching time Better response time

Other Examples u Robot control: single program, multiple concurrent operations u Airline reservations: one thread per customer  thread per task u Network server: single program, must handle concurrent requests from multiple users (examples: Web server)  thread pool

Sun Solaris 2 u Mixed approach  OS schedules light-weight process (LWP)  User-level library schedules user-level threads u User threads are cheap, can be thousands per task u Each LWP supports one or more user threads  LWPs are what we’ve been calling kernel threads  Solaris has entities called kernel threads; they are scheduling artifacts contained in the OS

Sun Solaris 2 (Mixed) Kernel thread Task 1 Task 2Task 3 CPU KERNEL Light weight process (LWP) User-level thread CPU

Examples of threads packages u POSIX-style threads:  OSF/DCE, Chorus threads, POSIX P1003.4a pthreads  SunOS Multi-Thread Architecture (Solaris 2)  IBM AIX 4.x, SCO UnixWare 2.0 u Microsoft-Style threads:  WIN32 threads (Window95, NT)  OS/2 threads (IBM OS/2) u Others: C Threads in Mach OS (now part of Macintosh OS X)