1 Confidential Enterprise Solutions Group Process and Threads.

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

3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Threads.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 What is a Process ? The activity of program execution. Also called a task or job Has associated with it: Code Data Resources A State An executing set.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
CSCE 351: Operating System Kernels
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
1 Chapter 4 Threads Threads: Resource ownership and execution.
Process Concept An operating system executes a variety of programs
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.
Phones OFF Please Processes Parminder Singh Kang Home:
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Introduction to Processes CS Intoduction to Operating Systems.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Threads and Thread Synchronization Advanced Windows Programming Series 1.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
1 Threads Chapter 11 from the book: Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date:
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
CS333 Intro to Operating Systems Jonathan Walpole.
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  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
1 OS Review Processes and Threads Chi Zhang
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
Operating System Concepts
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Threads and Thread Synchronization. Introduction In windows the basic unit of execution is the thread. It is the smallest schedulable unit of execution.
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4 – Thread Concepts
OPERATING SYSTEM CONCEPT AND PRACTISE
Processes and threads.
Chapter 3: Process Concept
PROCESS MANAGEMENT IN MACH
Chapter 4 – Thread Concepts
CS399 New Beginnings Jonathan Walpole.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Process Management Presented By Aditya Gupta Assistant Professor
Threads and Thread Synchronization
Threads and Locks.
System Structure and Process Model
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 4.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/49.
Chapter 3: Processes.
CS510 Operating System Foundations
Process Management -Compiled for CSIT
Chapter 4: Threads.
Presentation transcript:

1 Confidential Enterprise Solutions Group Process and Threads

2 Confidential Enterprise Solutions Group What is Process? they are generated they have a life each process has just one parent eventually they die they have one or more child ( optional)

3 Confidential Enterprise Solutions Group Process States 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.

4 Confidential Enterprise Solutions Group Doubt – Program Vs. Process A process invokes or initiates a program. It is an instance of a program that can be multiple and running the same application. Example:- Notepad is one program and can be opened twice. A process is a sequence of tasks.

5 Confidential Enterprise Solutions Group Process Conditions which terminate processes Normal exit (voluntary) Error exit (voluntary) Fatal error (involuntary) Killed by another process (involuntary)

6 Confidential Enterprise Solutions Group Threads What is thread? Threads are different parts of human being.

7 Confidential Enterprise Solutions Group Threads A thread is a path of execution through a program’s code, plus a set of resources (stack, register state, etc) assigned by the operating system. A thread lives in one and only one process. A process may have one or more threads. Each thread in the process has its own call stack, but shares process code and global data with other threads in the process. Pointers are process specific, so threads can share pointers.

8 Confidential Enterprise Solutions Group Process Vs Thread A Process is inert. A process never executes anything; it is simply a container for threads. Threads run in the context of a process. Each process has at least one thread. A thread represents a path of execution that has its own call stack and CPU state. Threads are confined to context of the process that created them. – A thread executes code and manipulates data within its process’s address space. – If two or more threads run in the context of a single process they share a common address space. They can execute the same code and manipulate the same data. – Threads sharing a common process can share kernel object handles because the handles belong to the process, not individual threads.

9 Confidential Enterprise Solutions Group Process Vs Thread

10 Confidential Enterprise Solutions Group Benefits from Multithreading – Improve application responsiveness E.g. a GUI thread to read from the user and another performing data base access. The GUI thread can respond to user commands, rather then doing them sequentially – Use multiple processors more efficiently – Improve program structure – Use fewer system resources

11 Confidential Enterprise Solutions Group Thread Data State which is maintained per thread basis – Thread ID – uniquely identifies a thread within a process – Register state – including PC, stack pointer – Stack – Signal Mask – Priority – Thread-Private storage

12 Confidential Enterprise Solutions Group Thread Synchronization Critical Section Mutex Event Semaphore we will have separate session on synchronization

13 Confidential Enterprise Solutions Group Hands on Windows Threads Write a program to create thread. Posix Threads Create a thread and print in loop

14 Confidential Enterprise Solutions Group Windows Thread HANDLE hThrd = (HANDLE)_beginthread(ThreadFunc, 0, &ThreadInfo); ThreadFunc – the function executed by the new thread void _cdecl ThreadFunc(void *pThreadInfo); pThreadInfo – pointer to input parameters for the thread For threads created with _beginthread the thread function, ThreadFunc, must be a global function or static member function of a class. It can not be a non-static member function.

15 Confidential Enterprise Solutions Group pThread pthread_t mythread; if( pthread_create(&mythread, NULL, thread_function, NULL)) ThreadFunc – the function executed by the new thread void * thread_function(void *arg) arg– pointer to input parameters for the thread pthread_join(mythread, NULL)

16 Confidential Enterprise Solutions Group

17 Confidential Enterprise Solutions Group Thread Synchronization Critical Section Mutex Event Semaphore

18 Confidential Enterprise Solutions Group Critical Section Used to synchronize between threads in single process Not kernel object

19 Confidential Enterprise Solutions Group Mutex Kernel Object Used to synchronize between threads in process and across process Named and Non-Named Mutex Ex: Single Instance of application

20 Confidential Enterprise Solutions Group Event Notifies one or more waiting threads that an event has occurred Auto Reset – Notifies one thread Manual Reset – Notifies one or more threads

21 Confidential Enterprise Solutions Group Semaphore Maintains a count between zero and some maximum value limiting the number of threads that are simultaneously accessing a shared resource The state of a semaphore object is signaled when its count is greater than zero, and nonsignaled when its count is equal to zero

22 Confidential Enterprise Solutions Group Sharing among process Child process can inherit Duplicate handle OpenMutex,OpenEvent…..

23 Confidential Enterprise Solutions Group Hands on critical section CRITICAL_SECTION m_cs; InitializeCriticalSection(&m_cs); UINT ThreadOne(LPVOID lParam) { // // Lock the Critical section EnterCriticalSection(&m_cs); // Some Process //Release the Critical section LeaveCriticalSection(&m_cs); return 0; } UINT ThreadTwo(LPVOID lParam) { // Lock the Critical section EnterCriticalSection(&m_cs); // Some Process //Release the Critical section L eaveCriticalSection(&m_cs); // return the thread return 0; }

24 Confidential Enterprise Solutions Group Job, Process, Thread & Fiber

25 Confidential Enterprise Solutions Group Job, Process, Thread & Fiber Mgmt. API Calls

26 Confidential Enterprise Solutions Group A kernel connects the application software to the hardware of a computerapplication software Manages task of computer and hardware Kernel objects are all those objects which are created and maintained by the Win32 kernel, like processes, threads, files, jobs, mailslots, mutexes, events

27 Confidential Enterprise Solutions Group

28 Confidential Enterprise Solutions Group Inter Process communication Pipe MailSlots Shared memory Sockets File mapping