Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Similar documents
OPERATING SYSTEM. Chapter 4: Threads

Chapter 4: Threads. Chapter 4: Threads

Chapter 4: Multithreaded Programming

Chapter 3: Processes

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Chapter 4: Threads. Operating System Concepts 9 th Edition

TDIU25: Operating Systems II. Processes, Threads and Scheduling

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 4: Multithreaded Programming

Chapter 4: Multithreaded Programming

Chapter 4: Multithreaded Programming

Chap 4, 5: Process. Dongkun Shin, SKKU

Chapter 3: Processes

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Chapter 3: Process Concept

Chapter 3: Process Concept

Chapter 4: Threads. Chapter 4: Threads

Chapter 3: Process Concept

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

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Operating System Design

CS307: Operating Systems

Chapter 3: Processes. Operating System Concepts 8th Edition

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

CSE 4/521 Introduction to Operating Systems

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Processes and Threads

Process Description and Control

CS420: Operating Systems

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

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

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Chapter 4: Multithreaded

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

CHAPTER 3 - PROCESS CONCEPT

CS370 Operating Systems Midterm Review

Chapter 3: Processes. Operating System Concepts 9 th Edition

CHAPTER 2: PROCESS MANAGEMENT

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

Concurrency, Thread. Dongkun Shin, SKKU

4.8 Summary. Practice Exercises

Chapter 4: Multi-Threaded Programming

Chapter 4: Multithreaded Programming Dr. Varin Chouvatut. Operating System Concepts 8 th Edition,

Lecture 2 Process Management

CS370 Operating Systems

Multithreaded Programming

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

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Chapter 3: Processes. Operating System Concepts 9 th Edition

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

Chapter 5: Threads. Outline

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Chapter 3: Process Concept

Chapter 4: Threads. Operating System Concepts 8 th Edition,

Chapter 3: Processes

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

CSE Opera,ng System Principles

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

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

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

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Operating Systems. Figure: Process States. 1 P a g e

Chapter 4: Threads. Operating System Concepts with Java 8 th Edition

CS 450 Operating System Week 4 Lecture Notes

Start of Lecture on January 22, 2014

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

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

Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts

Process. Program Vs. process. During execution, the process may be in one of the following states

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

Processes and Threads

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

CSC 539: Operating Systems Structure and Design. Spring 2006

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

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

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

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

CS Lecture 3! Threads! George Mason University! Spring 2010!

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

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

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

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

Processes and Threads

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

2/14/2012. Using a layered approach, the operating system is divided into N levels or layers. Also view as a stack of services

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Chapter 4 Multithreaded Programming

Killing Zombies, Working, Sleeping, and Spawning Children

Processes. Process Concept

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

W4118 Operating Systems. Junfeng Yang

SMD149 - Operating Systems

Transcription:

Lecture 3: Processes

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Process in General 3.3

Process Concept Process is an active program in execution; process execution must progress in sequential fashion Program is a passive entity stored on disk (executable file), and it becomes a process when executable file is loaded into memory One program can be executed multiple times generating multiple processes 3.4

Process Concept Process s parts The program code, also called text section Current activity including program counter, processor registers Stack containing temporary data like function parameters, return addresses, local variables Data section containing global variables Heap containing memory dynamically allocated during run time 3.5

Process Concept 3.6

Process State As a process executes, it changes 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 3.7

Diagram of Process State 3.8

Analogy CPU vs. Doctor Process 1 Process 2 Process 3 3.9

Process Control Block (PCB) Information associated with each process (also called task control block) Process state running, waiting, etc Program counter location of instruction to next execute CPU registers contents of all processcentric registers CPU scheduling information- priorities, scheduling queue pointers Memory-management information memory allocated to the process Accounting information CPU used, clock time elapsed since start, time limits I/O status information I/O devices allocated to process, list of open files 3.10

CPU Switch From Process to Process 3.11

Process Explorer- Freeware It shows a list of the currently active processes, including the names of their owning accounts if Process Explorer is in DLL mode you'll see the DLLs and memory-mapped files that the process has loaded. 3.12

Process Explorer The unique capabilities of Process Explorer make it useful for tracking down DLL-version problems or handle leaks, and provide insight into the way Windows and applications work. 3.13

Process Scheduling Process scheduler selects among available processes for next execution on CPU Maintains scheduling queues of processes Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device Processes migrate among the various queues 3.14

Representation of Process Scheduling Queueing diagram represents queues, resources, flows 3.15

Operations on Processes 1. Process Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes Generally, process identified and managed via a process identifier (pid) Resource sharing options: 1. Parent and children share all resources 2. Children share subset of parent s resources 3. Parent and child share no resources Execution options: 1. Parent and children execute concurrently 2. Parent waits until children terminate 3.16

A Tree of Processes init pid = 1 login pid = 8415 kthreadd pid = 2 sshd pid = 3028 bash pid = 8416 khelper pid = 6 pdflush pid = 200 sshd pid = 3610 ps pid = 9298 emacs pid = 9204 tcsch pid = 4005 3.17

2. Process Termination Process executes last statement and then asks the operating system to delete it using a system call. Returns status data from child to parent Process resources are de-allocated by operating system Parent may terminate the execution of children processes using a system call. Some reasons for doing so: Child has exceeded allocated resources Task assigned to child is no longer required The parent is exiting 3.18

Interprocess Communication Processes within a system may be independent or cooperating Cooperating process can affect or be affected by other processes, including sharing data Cooperating processes need interprocess communication (IPC) Two models of IPC Shared memory Message passing 3.19

Communications Models (a) Message passing. (b) shared memory. 3.20

Threads

Introduction Most modern applications are multithreaded, Threads run within application Multiple tasks with the application can be implemented by separate threads Update display Fetch data Spell checking Answer a network request Process creation is heavy-weight while thread creation is light-weight Can simplify code, increase efficiency 4.2

Multi-threaded Process Analogy 4.3

Multithreaded Server Architecture Example 4.4

Benefits Responsiveness may allow continued execution if part of process is blocked, especially important for user interfaces Resource Sharing threads share resources of process, easier than shared memory or message passing Economy cheaper than process creation, thread switching lower overhead than context switching Scalability process can take advantage of multiprocessor architectures 4.5

Multicore Programming Multicore or multiprocessor systems putting pressure on programmers, challenges include: Dividing activities Balance Data splitting Data dependency Testing and debugging Parallelism implies a system can perform more than one task simultaneously Concurrency supports more than one task making progress, this can be implemented by a Single processor / core with a scheduler. 4.6

Concurrency vs. Parallelism Concurrent execution on single-core system: Parallelism on a multi-core system: 4.7

Single and Multithreaded Processes 4.8

Amdahl s Law Identifies performance gains from adding additional cores to an application that has both serial and parallel components S is serial portion N processing cores That is, if application is 75% parallel / 25% serial, moving from 1 to 2 cores results in speedup of 1.6 times As N approaches infinity, speedup approaches 1 / S Serial portion of an application is limiting the performance gained by adding additional cores 4.9

Amdahl s Law 4.10

Amdahl s Law Adding more processors leads to successively smaller returns in terms of speedup Using 16 processors does not results in an anticipated 16-fold speedup The Non-parallelizable sections of code takes a larger percentage of the execution time as the loop time is reduced Maximum Speedup is theoretically limited by fraction f of serial code So even 1% serial code implies speedup of 100 at best! 4.11

User Threads and Kernel Threads User threads - management done by user-level threads library. Three primary thread libraries: POSIX Pthreads Windows threads Java threads Kernel threads - Supported by the Kernel Examples virtually all general purpose operating systems, including: Windows Linux Mac OS X 4.12

Implicit Threading Growing in popularity as numbers of threads increase, program correctness more difficult with explicit threads Creation and management of threads done by compilers and run-time libraries rather than programmers 4.13

Thread Cancellation Terminating a thread before it has finished Thread to be canceled is target thread Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled 4.14

Operating System Examples Windows Threads Linux Threads 4.15

Windows Threads Windows implements the Windows API primary API for Win 98, Win NT, Win 2000, Win XP, and Win 7 Each thread contains A thread id Register set representing state of processor Separate user and kernel stacks for when thread runs in user mode or kernel mode Private data storage area used by run-time libraries and dynamic link libraries (DLLs) The register set, stacks, and private storage area are known as the context of the thread 4.16

Linux Threads Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process) Flags control behavior struct task_struct points to process data structures (shared or unique) 4.17