Processes and Threads

Similar documents
OPERATING SYSTEMS. Systems with Multi-programming. CS 3502 Spring Chapter 4

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Process Description and Control

Process- Concept &Process Scheduling OPERATING SYSTEMS

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Chapter 3 Process Description and Control

Process Description and Control. Chapter 3

Processes and Threads

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

System Call. Preview. System Call. System Call. System Call 9/7/2018

CSC 539: Operating Systems Structure and Design. Spring 2006

Learning Outcomes. Processes and Threads. Major Requirements of an Operating System. Processes and Threads

Major Requirements of an OS

CHAPTER 2: PROCESS MANAGEMENT

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Process Description and Control

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Chapter 2 Processes and Threads

CS510 Operating System Foundations. Jonathan Walpole

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Process Characteristics

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Computer Systems II. First Two Major Computer System Evolution Steps

Chapter 3: Processes

Chapter 5: CPU Scheduling

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

Announcement. Exercise #2 will be out today. Due date is next Monday

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

OPERATING SYSTEMS: Lesson 4: Process Scheduling

PROCESSES Gursharan Singh Tatla 24/01/2011

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

SMD149 - Operating Systems

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Course: Operating Systems Instructor: M Umair. M Umair

Chapter 3: Process Concept

Chapter 3: Process Concept

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

operating system Spring 2017 Prof.Dr. Hasan Balik Student Name : Walid.W. Ramadan mansour Student ID :

Threads Chapter 5 1 Chapter 5

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Chapter 3: Process Concept

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Frequently asked questions from the previous class survey

Chap 4, 5: Process. Dongkun Shin, SKKU

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru Department of Electronics and Communication Engineering

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Announcements Processes: Part II. Operating Systems. Autumn CS4023

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

CS370 Operating Systems

Process Description and Control. Chapter 3

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

CS3733: Operating Systems

1.1 CPU I/O Burst Cycle

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

4. Concurrency via Threads

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

آنستیتیوت تکنالوجی معلوماتی و مخابراتی ICTI

CS370 Operating Systems

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Process Description and Control. Major Requirements of an Operating System

UNIT 3. PROCESS MANAGEMENT

Major Requirements of an Operating System Process Description and Control

Announcements. Operating Systems. Autumn CS4023

CS 3733 Operating Systems

Process. Discussion session 3 1/30/2016

Chapter 3: Processes. Operating System Concepts 8th Edition,

Lecture 5: Process Description and Control Multithreading Basics in Interprocess communication Introduction to multiprocessors

Operating System Concepts Ch. 5: Scheduling

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Diagram of Process State Process Control Block (PCB)

TDIU25: Operating Systems II. Processes, Threads and Scheduling

Lecture 2 Process Management

Process Characteristics. Threads Chapter 4. Process Characteristics. Multithreading vs. Single threading

Threads Chapter 4. Reading: 4.1,4.4, 4.5

Process Scheduling Queues

Processes and Threads. Processes: Review

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

CSE325 Principles of Operating Systems. Processes. David P. Duggan February 1, 2011

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Unit 3 : Process Management

Transcription:

OPERATING SYSTEMS CS3502 Spring 2018 Processes and Threads (Chapter 2)

Processes Two important types of dynamic entities in a computer system are processes and threads. Dynamic entities only exist at execution time, and their behavior exhibits state changes. A process is basically a program in memory either in execution or waiting to execute, I/O, or other service. A process is the fundamental computational unit that requests various types of services in the computer system. Processes and threads are handled by the process manager module of the operating system.

Processes and Threads Several processes can be active at a time (O.S with multiprogramming) Only one process is actually running at any instant of time (in a single-processor system) The OS switches the processor from one process to another Each process can have several threads running within it

Process Creation On a typical operating system, a process is created In response to a new job arriving A new user who carries out a login A currently executing process that creates a new process. A process is created if there is sufficient memory available; creating the process waits if other resources it needs are not available.

Process Behavior A process requests processor and I/O servicing at various times and usually will have to wait for these services. The OS maintains a waiting line or queue of processes for every one of these services. At some point in time, a process will be in a queue waiting for processor service. At some other point in time, the process will be in a different queue waiting for I/O service. When a process completes all service requests, it terminates and exits the system.

System Resources Active resources: CPU, I/O devices Passive resources: memory

Process States Created Ready (waiting in the ready queue a processor) Running (executing) Blocked (suspended and waiting for I/O or other event) I/O processing Waiting for passive resources Interrupted by the OS Terminated

Process State Diagram Represents the various states of a process and the possible transitions in the behavior of a process. Each state is indicated by a rounded oval and the arrows connecting the states are the transitions from one state to the next. The small black circle denotes that the state it points to is the initial state. In a similar manner, the state before the hollow small circle indicates that it is the last state in the behavior of a process. Normally a process spends a short finite time in every state.

Process State-Transition Diagram

Process Descriptor Also called process control block (PCB) A data structure in which the OS maintains data about a process.

Data in a Process Descriptor Each process is represented by its own PCB Process name Process state Program counter CPU registers I/O status Memory information Accounting information Scheduler information (priority, queues, ) List of resources

Threads A Thread is: A light-weight process A single execution sequence of a process A component of a process Shares with other threads code and resources allocated to the process Most OSs support multi-threading: several threads in a process

Multiple Threads In addition to multiple processes, modern operating systems support other computational units known as threads, a lightweight process. A thread is a dynamic component of a process. Several threads are usually created within a single process. These threads share part of the program code and the resources of the process. Most modern operating systems support multiple processes and multiple threads of execution within a single process, this feature is called multi-threading.

Threads Executing in a Process

Threads in a Process The operating system manages processes and threads in a multiprogramming environment The execution of threads are handled much more efficiently than the execution of processes. The modern view of threads represents them as the active elements of computation within a process. All threads that belong to a process share the state and resources of the process.

Thread Attributes Execution state Context, its own program counter within the process Execution stack Local memory block (for local variables) Reference to parent process to access the shared resources allocated to the process

Thread Descriptor A thread descriptor is a data structure used by the OS to store all the relevant data of a thread. It contains the following fields: thread identifier execution state of the thread the process owner of the thread list of related threads execution stack thread priority thread-specific resources Some of the fields of a thread descriptor also appear as part of the corresponding process descriptor.

Thread States Threads have their own execution state, context, execution stack, local memory (for local variables), in addition to the resources allocated to the process. When a process is created, only one thread is created called the base thread of the process; then other threads of the process may be created by the process or by the base thread. A process can have a single thread; in this case it is considered a simple process because it has only one thread of execution.

Types of Threads There are two general types of threads: User-level threads (ULT) Kernel-level threads (KLT).

User-level Threads With the user-level threads, the thread management is carried out at the level of the application without kernel intervention. The application carries out threads management using a thread library, such as the POSIX Pthreads Library. Using this library, the application invokes the appropriate functions for the various thread management tasks such as: creating, suspending, and terminating threads.

Kernel-Level Threads The thread management tasks are carried out by the kernel. A process that needs these thread handling services has to use the API to the kernel thread facility. One of the advantages of kernel-level threads is that the process will not be blocked if one of its threads becomes blocked. Another advantage is that the possibility of scheduling multiple threads on multiple processors.

Multiprogramming Process management is one of the major functions of the operating system; it involves creating processes and controlling their execution. In most operating systems, several processes are stored in memory at the same time and the operating system (OS) manages the sharing of the CPU and other resources among the various processes. This facility of the operating system is called multiprogramming.

Multiprogramming (2) One of the requirements of multiprogramming is that the OS must allocate the processor(s) and other resources to the various processes in such a way that these active resources are maintained busy the longest period possible. If there is only one processor, then only one process can be in execution at any given time. The other processes are ready, waiting for processor service. Processes also request access to passive resources, such as memory.

Context Switch When the OS switches the processor to another process, the OS must save the context of the current process and load the (saved) context of the new process Context switch time is short and is overhead time Context switch time is dependent on hardware support

Degree of Multiprogramming The number of processes that the system supports in memory is known as the degree of multiprogramming.

Multi-Programming (2) In most computer systems, the I/O controllers enable a system to overlap device I/O operation with processor (CPU) operation. This results in a higher utilization of the system facilities Several processes can be in memory at a time; one receiving CPU service and another receiving I/O service, the others are waiting.

Processes and Multiprogramming With multiprogramming, several processes can be active at a time Only one process is actually running at any instant of time (if there is only a single CPU) The OS switches rapidly the CPU from one process to another (context switching) The selection of which process to run next is made by the scheduler

Features Needed for Multiprogramming I/O routines supplied by the system Memory management Processor scheduling Allocation of devices

Service Requests A process will require (demand) several processor and I/O requests The total processor request of a process is divided into shorter service periods: each one is known as a CPU burst The total I/O request is divided into shorter service periods called I/O bursts In normal behavior of a process, it alternates between a CPU and I/O burst

Total Processor Demand The total processor service demand for a process is the sum of all its CPU bursts Each CPU burst has a different duration The total CPU service time requested by process P i is: i = 1 + 2 +... m

Total I/O Service Demand The total I/O service demand for a process is the sum of all its I/O bursts Each I/O burst has a different duration, The total I/O service time requested by process P i is: i = 1 + 2 +... n

Batch OS with I/O

Interrupts and Context Switches A context switch occurs when: The executing process completes its current CPU burst and needs an I/O operation, such as reading data from a file. The executing process is interrupted by a timer under OS control. The process is returned to its ready state in the wait line for CPU service, the ready queue. A high priority process arrives into the ready queue, the OS interrupts the running process if it has a lower priority.

CPU and I/O Queues