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

Similar documents
ECE519 Advanced Operating Systems

Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

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

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

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

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

Process Characteristics

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

Database Management System

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

Threads Chapter 5 1 Chapter 5

Chapter 4 Threads, SMP, and

Database Management System

Software Engineering

Processes, Threads, SMP, and Microkernels

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

Chapter 3 Process Description and Control

Multithreading. Reading: Silberschatz chapter 5 Additional Reading: Stallings chapter 4

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

Threads Chapter 4. Reading: 4.1,4.4, 4.5

CSE 306/506 Operating Systems Threads. YoungMin Kwon

Information System Audit Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

Information System Audit Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

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

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

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

Information System Audit Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

2017 Pearson Educa2on, Inc., Hoboken, NJ. All rights reserved.

Process Description and Control

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

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

Operating System 4 THREADS, SMP AND MICROKERNELS

Threads, SMP, and Microkernels

Threads. CS3026 Operating Systems Lecture 06

Information System Audit Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

CHAPTER 2: PROCESS MANAGEMENT

Processes. CS3026 Operating Systems Lecture 05

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

Threads, SMP, and Microkernels. Chapter 4

Operating Systems. Chapter 4 Threads. Lei Duan

Software Engineering

Processes and Threads

Introduction to Computing

Introduction to Computing

Software Engineering

CSC 716 Advanced Operating System Fall 2007 Exam 1. Answer all the questions. The maximum credit for each question is as shown.

Processes and Threads

UNIT 3. PROCESS MANAGEMENT

CSCE 313: Intro to Computer Systems

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSE 153 Design of Operating Systems Fall 2018

4. Concurrency via Threads

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

CS510 Operating System Foundations. Jonathan Walpole

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

Exercise (could be a quiz) Solution. Concurrent Programming. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - IV Threads

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

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

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

Lecture 2 Process Management

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

* What are the different states for a task in an OS?

3.1 Introduction. Computers perform operations concurrently

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

Operating Systems. Lecture 4. Nachos Appetizer

CHAPTER 3 - PROCESS CONCEPT

Process Description and Control

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

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

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

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

Processes and Threads

Chapter 4: Threads. Chapter 4: Threads

Process Description and Control. Chapter 3

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

OPERATING SYSTEM. Chapter 4: Threads

Definition Multithreading Models Threading Issues Pthreads (Unix)

Chapter 3: Processes. Operating System Concepts 8th Edition

OS Main Goals. 10/24/2013 Operating Systems, Beykent University 1

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

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

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Lecture 4: Process Management

CISC2200 Threads Spring 2015

Process Description and Control. Chapter 3

Chapter 4: Processes. Process Concept

Chapter 5: Threads. Outline

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Chapter 4: Processes

Processes and Threads

CSE 4/521 Introduction to Operating Systems

Computer Systems II. First Two Major Computer System Evolution Steps

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

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Operating System Architecture. CS3026 Operating Systems Lecture 03

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Chapter 4: Multithreaded Programming

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

Chapter 4: Threads. Chapter 4: Threads

Transcription:

Operating Systems Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) armahmood786@yahoo.com alphasecure@gmail.com alphapeeler.sf.net/pubkeys/pkey.htm http://alphapeeler.sourceforge.net pk.linkedin.com/in/armahmood http://alphapeeler.tumblr.com www.twitter.com/alphapeeler armahmood786@jabber.org www.facebook.com/alphapeeler alphapeeler@aim.com abdulmahmood-sss alphasecure mahmood_cubix 48660186 armahmood786@hotmail.com alphapeeler@icloud.com http://alphapeeler.sf.net/me http://alphapeeler.sf.net/acms/ VC++, VB, ASP

Processes and Threads Processes have two characteristics: Resource Ownership Process includes a virtual address space to hold the process image the OS performs a protection function to prevent unwanted interference between processes with respect to resources Scheduling/Execution Follows an execution path that may be interleaved with other processes a process has an execution state (Running, Ready, etc.) and a dispatching priority and is scheduled and dispatched by the OS

Processes and Threads The unit of dispatching is referred to as a thread or lightweight process The unit of resource ownership is referred to as a process or task Multithreading - The ability of an OS to support multiple, concurrent paths of execution within a single process

Single Threaded Approaches A single thread of execution per process, in which the concept of a thread is not recognized, is referred to as a single-threaded approach MS-DOS some variants - UNIX JRE MS-DOS is an example Windows, Solaris, modern UNIX, Linux

Processes - Multithreaded environment In multi-threaded env. Process is defined as : unit of resource allocation and a unit of protection Associated items with processes: virtual address space that holds the process image Protected access to: processors other processes files I/O resources

One or More Threads in a Process Each thread has: an execution state (Running, Ready, etc.) saved thread context (program counter) when not running an execution stack some per-thread static storage for local variables access to the memory and resources of its process (all threads of a process share this)

Threads vs. Processes Thread control block: register values, priority, thread-related state info. All threads shares : PCB, process address space, access to the same data. What happens when one thread alters data in memory? What happens when one thread opens a file with read privileges?

Benefits of Threads Takes less time to create a new thread than a process Less time to terminate a thread than a process Switching between two threads takes less time than switching between processes Threads enhance efficiency in communication between programs Because threads within same process share memory and files, they can communicate with each other without invoking the kernel.

Uses of Thread in a Single-User Multiprocessing System Foreground and background work one thread could display menus and read user input, while another thread executes user commands and updates the spreadsheet. Asynchronous processing word processor to write its random access memory (RAM) buffer to disk once every minute. Speed of execution process can compute one batch of data while reading the next batch from a device. Modular program structure easier to design and implement using threads.

In an OS that supports threads, scheduling and dispatching is done on a thread basis Most of the state information dealing with execution is maintained in thread-level data structures suspending a process involves suspending all threads of the process termination of a process terminates all threads within the process

The key states for a thread are: Running Ready Blocked Thread operations associated with a change in thread state are: Spawn Block Unblock Finish

RPC Using Single Thread Scenario: program that performs two remote procedure calls (RPCs) 2 to two different hosts, using a single thread.

RPC Using One Thread per Server Scenario: program that performs two remote procedure calls (RPCs) 2 to two different hosts, using a multiple threads.

Multithreading on a Uniprocessor On a uniprocessor, multiprogramming enables the interleaving of multiple threads within multiple processes. Scenario: three threads in two processes are interleaved on the processor.

Thread Synchronization It is necessary to synchronize the activities of the various threads all threads of a process share the same address space and other resources any alteration of a resource by one thread affects the other threads in the same process

Types of Threads User Level Thread (ULT) Kernel level Thread (KLT)

User-Level Threads (ULTs) All thread management is done by the application The kernel is not aware of the existence of threads

Relationships Between ULT States and Process States Figure 4.6 Examples of the Relationships between User-Level Thread States and Process States

Scheduling can be application specific ULTs can run on any OS Thread switching does not require kernel mode privileges

Disadvantages of ULTs In a typical OS many system calls are blocking as a result, when a ULT executes a system call, not only is that thread blocked, but all of the threads within the process are blocked In a pure ULT strategy, a multithreaded application cannot take advantage of multiprocessing (multi-processor or multi-core) Reason: A kernel assigns one process to only one processor at a time

Overcoming ULT Disadvantages (1) Jacketing -- converts a blocking system call into a non-blocking system call (2) Writing an application as multiple processes rather than multiple threads

Kernel-Level Threads (KLTs) Thread management is done by the kernel no thread management is done by the application API to kernel thread facility MS Windows is an example of this approach

Advantages of KLTs The kernel can simultaneously schedule multiple threads from the same process on multiple processors If one thread in a process is blocked, the kernel can schedule another thread of the same process Kernel routines can be multithreaded

Disadvantage of KLTs The transfer of control from one thread to another within the same process requires a mode switch to the kernel

Combined Approaches Thread creation is done in the user space Bulk of scheduling and synchronization of threads is by the application Solaris is an example

Multicore and Multithreding Performance of software on multicore: If only 10% of the code is inherently serial (f = 0.9), running the program on a multicore system with eight processors yields a performance gain of only a factor of 4.7

Applications That Benefit Multithreaded native applications characterized by having a small number of highly threaded processes Multiprocess applications characterized by the presence of many single-threaded processes Java applications Multiinstance applications multiple instances of the application in parallel

Fork() It is a system call that creates a new process under the UNIX operating system. It takes no arguments. The purpose of fork() is to create a new process, which becomes the child process of the caller. After a new child process is created, both processes will execute the next instruction following the fork() system call. Therefore, we have to distinguish the parent from the child.

Fork() returned value of fork(): * If fork() returns a negative value, the creation of a child process was unsuccessful. * fork() returns a zero to the newly created child process. * fork() returns a positive value, the process ID of the child process, to the parent. The returned process ID is of type pid_t defined in sys/types.h. Normally, the process ID is an integer. Moreover, a process can use function getpid() to retrieve the process ID assigned to this process.

Fork() Example: #include <stdio.h> #include <sys/types.h> int main() { printf( Before Forking\n ); fork(); printf( After Forking\n ); return 0; } =========================== > vi test.c > gcc test.c -o test.bin >./test.bin Before Forking After Forking After Forking