1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.

Slides:



Advertisements
Similar presentations
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
Advertisements

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
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.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Chapter 5 Processes and Threads Copyright © 2008.
Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Threads CSCI 444/544 Operating Systems Fall 2008.
Chapter 3: Processes. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
Client-Server Communication Sockets Remote Procedure Calls Remote Method Invocation (Java)
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Processes & Threads Emery Berger and Mark Corner University.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Assistant Professor, University of Maryland Baltimore County.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Outline n Process Concept n Process.
1 11/1/2015 Chapter 4: Processes l Process Concept l Process Scheduling l Operations on Processes l Cooperating Processes l Interprocess Communication.
Threads G.Anuradha (Reference : William Stallings)
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 3 Operating Systems.
Chapter 3: Process-Concept. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
3.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Overview: Process Concept Process Scheduling Operations on Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
Department of Computer Science and Software Engineering
Lecture 3 Threads Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Operating System Concepts
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter three.  An operating system executes a variety of programs:  A batch system executes jobs.  A time-shared systems has user programs or tasks.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
Client-Server Communication
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
CMSC621: Advanced Operating Systems Advanced Operating Systems
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Processes Overview: Process Concept Process Scheduling
Threads & multithreading
CMSC621: Advanced Operating Systems Advanced Operating Systems
Chapter 4: Threads.
Chapter 4: Processes Process Concept Process Scheduling
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
CSE 451: Operating Systems Winter 2011 Processes
Threads and Concurrency
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Chapter 4: Threads.
Presentation transcript:

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof. Mark Corner and Prof. Emery Berger’s OS course at Umass Amherst Assistant Professor, University of Maryland Baltimore County

2 Announcements Readings from Silberchatz [4 th chapter] Project 1 is out Homework 2 would be out end of this week Homework 1 grades are out

3 POSIX Signals Linux kernel Process 1Process 2 Register a signal deliver a signal  NameDescriptionDefault Action SIGINT Interrupt character typedterminate process SIGQUIT Quit character typed ( ^\ )create core image SIGKILLkill -9 terminate process SIGSEGV Invalid memory referencecreate core image SIGPIPE Write on pipe but no reader terminate process SIGALRMalarm() clock ‘rings’terminate process SIGUSR1 user-defined signal typeterminate process SIGUSR2 user-defined signal typeterminate process

4 signals int kill( pid_t pid, int signo ); –Send a signal to a process with a process id signal(, ) –Handle a maskable signal in your code

5 Message Passing Using Sockets A socket is defined as an endpoint for communication Concatenation of IP address and port The socket :1625 refers to port 1625 on host Communication consists between a pair of sockets

6 Message Passing Using Sockets

7 Concept of Remote Procedure calls n Remote procedure call (RPC) abstracts procedure calls between processes on networked systems n Stubs – client-side proxy for the actual procedure on the server n The client-side stub locates the server and marshalls the parameters n The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server

Execution of RPC

9 A Step back: Definition of a Process n One or more threads running in an address space

10 What is an address space? n A collection of data and code for the program organized in an memory (addressable) region

11 Why do we need processes? n A process (with a single thread) supports a serial flow of execution n Is that good enough for all purposes? n What if something goes wrong in one process? n What if something takes a long amount of time in one process? n What if we have more than one user?

12 Processes Vs Threads n Both abstractions are very important n They can provide parallel programming & concurrency n They can hide latency from the end user n Maximize CPU utilization n Handle multiple, asynchronous events n But they support different programming styles, have different performances

13 What is difference between Process and Threads n The execution context of the process are (Program Counter, registers), address space, files, mmaped regions etc.

14 What is difference between Process and Threads n Threads share an address space. They have same files, sockets etc. n They have their own stack, program counters, registers, and stack specific data

15 Creating Threads n UNIX n Pthreads (POSIX threads) n Pthread_create() --- creating a thread n Pthread_join() --- wait for thread to finish Lets see a demonstration of using pthreads.

16 Scheduling One-one (linux)Many-one (Green Threads) Many-many (Window-NT)

17 When to use Threads and When to use processes n Processes or Threads n Performance? n Flexibility/Ease-of-use n Robustness n Simple Scheduling n OS has a list of Threads and schedules them similar to Processes. In Linux, threads/processes treated similarly n Chooses one of the threads and loads them to be run n Runs them for a while, runs another.

18 How does it work in Linux n 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) n struct task_struct points to process data structures (shared or unique)

19 Threads Vs Processes n Processes or Threads n Performance? n Flexibility/Ease-of-use n Robustness n Simple Scheduling n OS has a list of Threads and schedules them similar to Processes. In Linux, threads/processes treated similarly n Chooses one of the threads and loads them to be run n Runs them for a while, runs another.

20 Flexibility/Ease of use? n Process are more flexible n Easy to spawn processes, I can ssh into a server and spawn a process n Can communicate over sockets= distributes across machines n Threads n Communicate using memory – must be on the same machine n Requires thread-safe code

21 Robustness n Process are more robust n Processes are separate or sandboxed from other processes n If one process dies, no effect on other processes n Threads n If one thread crashes, whole process terminates n Since there is sharing, there are problems with using the stack efficiently

22 An in-class discussion