Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

Chapter 3 Process Description and Control
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Processes CSCI 444/544 Operating Systems Fall 2008.
Review: Process Management Objective: –Enable fair multi-user, multiprocess computing on limited physical resources –Security and efficiency Process: running.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Processes and Resources
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Process Concept An operating system executes a variety of programs
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
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.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
Exam Review Operating Systems CS 550. Items of Interest Exam is Nov. 19, 2014 Focus on material since last exam, though knowledge of initial material.
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Scheduling Example 3 (1) Assume: FIFO Job Scheduling 100 K Main Memory Processor Sharing Process Scheduling (Cont…)
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Chapter 5 Processor Scheduling Introduction Processor (CPU) scheduling is the sharing of the processor(s) among the processes in the ready queue.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
Introduction to Embedded Systems More on Synchronization and Deadlocks Lecture 16.
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.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
What is an Operating System? Various systems and their pros and cons –E.g. multi-tasking vs. Batch OS definitions –Resource allocator –Control program.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
CS333 Intro to Operating Systems Jonathan Walpole.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Unit 4: Processes, Threads & Deadlocks June 2012 Kaplan University 1.
Processes 2 Introduction to Operating Systems: Module 4.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
CPU Scheduling Operating Systems CS 550. Last Time Deadlock Detection and Recovery Methods to handle deadlock – Ignore it! – Detect and Recover – Avoidance.
Introduction to operating systems What is an operating system? An operating system is a program that, from a programmer’s perspective, adds a variety of.
Big Picture Lab 4 Operating Systems C Andras Moritz
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process concept.
CS 6560: Operating Systems Design
Applied Operating System Concepts -
Operating Systems: A Modern Perspective, Chapter 6
Intro to Processes CSSE 332 Operating Systems
Process management Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads and Concurrency
Concurrency: Mutual Exclusion and Process Synchronization
February 5, 2004 Adrienne Noble
Foundations and Definitions
Chapter 6: Scheduling Algorithms Dr. Amjad Ali
CSE 153 Design of Operating Systems Winter 2019
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Intro to OS CUCS Mossé Processes and Threads What is a process? What is a thread? What types? A program has one or more locus of execution. Each execution is called a thread of execution. The set of threads comprise a process. Not an object or executable files: must be executing Each thread contains: –an instruction pointer (IP), a register with next instruction. –a stack for temporary data (eg, return addresses, parameters) –a data area for data declared globally and statically A process/thread is active, while a program is not.

Intro to OS CUCS Mossé How to run a program The executable code is loaded onto memory (where?) Space is allocated to variables (what types of vars?) A stack is allocated to the process (for what?) Registers are updated (which registers?) Control (of execution) goes to the process (how?) Process runs one instruction at a time, in a cycle: –fetch the instruction from memory –decode the instruction –update the IP –execute the instruction

Intro to OS CUCS Mossé Processes and Threads (revisited) Address space: memory reserved for a process A heavyweight process has a single locus of execution per address space, a single IP, a single PCB A Process Control Block (PCB) contains information pertaining to the process itself –state (running, ready, etc) –registers and flags (stack pointer, IP, etc) –resource information (memory/CPU usage, open files, etc) –process ID –security and protection information –accounting info (who to bill, limits, similar to resource info)

Intro to OS CUCS Mossé Processes and Threads (cont) Thread (lightweight process) of a process share some resources (e.g., memory, open files, etc) Threads have their own stack, IP, local address space With only a single process in memory, easy to manage For example, if a process requests IO (eg, read from keyboard), it just stays in the memory waiting Several threads or processes complicate things; when IO is requested, why make other processes wait? Context switching takes place… take a waiting thread “out of the CPU” and put a thread that is ready in CPU

Intro to OS CUCS Mossé State Diagram Create: PCB and other resources are setup End: resources held are returned to the OS (freed) Context switching: saves HW context; updates PCB States are typically implemented as queues, lists, sets end ready blocked running create dispatch Quantum expired IO completed IO requested process completed process initialized

Intro to OS CUCS Mossé These two states check for sufficient resources in the system Complete State Diagram process started end ready blocked running create IO completed IO requested process completed admission control suspended process submitted temporary suspension process returns dispatch Quantum expired

Intro to OS CUCS Mossé Multiple Threads and Processes Several problems with multitasking: –fairness in usage of CPU –fairness in usage of other resources –coordinated input and output –lack of progress (deadlocks and livelocks) –synchronization: access to the same data item by several processes/threads (typical example, deposits into account)

Intro to OS CUCS Mossé Synchronization Example At time t=6 T2 requests the withdrawal of $200 (and gets preempted); at t=8 T1 requests the deposit of $200; t=9, T1 reads balance ($300); at t=10, T2 adds $200, at t=11, T1 writes new balance; at t=12, T2 resumes and reads balance; at t=13, T2 subtracts $200; at t=14, T2 writes new balance What if order was changed: 6, 8, 9, 12, 13, 14, 10, 11? Other combinations? T2req T1req T1r T1c T1w T2r T2c T2w

Intro to OS CUCS Mossé More on Synchronization Semaphores and primitives serve to achieve mutual exclusion and synchronized access to resources Clearly, there is more delays associated with attemp- ting to access a resource protected by semaphores Non-preemptive scheduling solves that problem As an aside: –Which scheduling mechanism is more efficient? Preemptive or non-preemptive? –Within each type of scheduling (pr or non-pr), one can choose which policy he/she wants to use

Intro to OS CUCS Mossé Using Semaphores When threads use semaphores, they are attempting to reserve a resource for usage. Only the threads that succeed are allowed in the CS. If there is a thread in the CS already, other requesting threads are blocked, waiting on an event When the thread exits the CS, the OS unblocks the waiting thread, typically during the V(s) sys_call The now unblocked thread becomes ready The OS may decide to invoke the scheduler… or not

Intro to OS CUCS Mossé Types of Synchronization There are 2 basic types of sync: P1:: P(s1) … V(s1) P2:: P(s1) … V(s1) P2:: P(s2) … V(s1) P1:: P(s1) … V(s2) MUTEX BARRIER SYNC

Intro to OS CUCS Mossé Deadlocks When a program is written carelessly, it may cause a… DEADLOCK!!! Each process will wait for the other process indefinitely How can we deal with these abnormalities? Avoidance, prevention, or detection and resolution Which one is more efficient? P1:: P(s1) P(s2) … V(s2) V(s1) P2:: P(s2) P(s1) … V(s1) V(s2)

Intro to OS CUCS Mossé Dining Philosophers There were some hungry philosophers, and some angry philosophers (not the same, not Rastas) Each needed two forks, each shared both his/her forks Possible deadlock situation! HOW? Is it possible to have a (literally) starvation situation? What is the best solution? –Round-robin? FIFO? How good are FIFO and RR? Important: what is the metric to judge a solution by? –Least overhead? Minimum starvation? –How to evaluate fairness?