Operating Systems Yasir Kiani. 22-Sep-20062 Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread.

Slides:



Advertisements
Similar presentations
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Advertisements

Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
Chapter 13 Processes. What is a process? A process is a program in execution A process is created whenever an external command is executed Whenever the.
Operating Systems Yasir Kiani. 20-Sep Agenda for Today Review of previous lecture Use of FIFOs in a program Example code Process management commands.
1 Created by Another Process Reason: modeling concurrent sub-tasks Fetch large amount data from network and process them Two sub-tasks: fetching  processing.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Processes CSCI 444/544 Operating Systems Fall 2008.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Threads CSCI 444/544 Operating Systems Fall 2008.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Process Concept An operating system executes a variety of programs
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Process states inWindows 2000 and Linux Module 2.1.
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Process Control. Module 11 Process Control ♦ Introduction ► A process is a running occurrence of a program, including all variables and other conditions.
Operating Systems 1 K. Salah Module 2.0: Processes Process Concept Trace of Processes Process Context Context Switching Threads –ULT –KLT.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
30 October Agenda for Today Introduction and purpose of the course Introduction and purpose of the course Organization of a computer system Organization.
The kernel considers each program running on your system to be a process A process lives as it executes, with a lifetime that may be short or long A process.
Operating Systems CSE 411 CPU Management Sept Lecture 9 Instructor: Bhuvan Urgaonkar.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
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.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Week Fourteen Agenda Announcements Final Exam True/False -100 questions (1 point per question) Multiple Choice - 40 questions (2 points per question)
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Operating Systems CMPSC 473 Processes (6) September Lecture 12 Instructor: Bhuvan Urgaonkar.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CSC 322 Operating Systems Concepts Lecture - 7: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CSC 360, Instructor: Kui Wu Thread & PThread. CSC 360, Instructor: Kui Wu Agenda 1.What is thread? 2.User vs kernel threads 3.Thread models 4.Thread issues.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
Agenda Managing Processes (Jobs) Command Grouping Running jobs in background (bg) Bringing jobs to foreground (fg), Background job status (jobs) Suspending.
Operating System Concepts
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
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.
Introduction to threads
OPERATING SYSTEM CONCEPT AND PRACTISE
CS 6560: Operating Systems Design
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Threads and Cooperation
Threads & multithreading
Operating Systems Lecture 13.
Operating System Concepts
Threads and Data Sharing
Operating Systems Lecture 12.
Mid Term review CSC345.
Threads Chapter 4.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Inter-Process Communication ENCE 360
Operating Systems Lecture 1.
CS510 Operating System Foundations
Chapter 4: Threads.
Lecture 6 Introduction to Process Management
Presentation transcript:

Operating Systems Yasir Kiani

22-Sep Agenda for Today Review of previous lecture Process management commands: bg, fg, ^Z, jobs, ^C, kill Thread concept Pros and cons of threads User and kernel threads Pthreads library with example Recap of lecture

22-Sep Review of Lecture 11 Use of FIFOs in a program Sample code Process management in UNIX/Linux UNIX/Linux commands/calls: mknod, mkfifo, ps, top

22-Sep The fg Command  fg [%job_id]  fg resumes the execution of a suspended job in the foreground and moves a background job into the foreground.  If %job_id is omitted the current job is assumed.

22-Sep The bg command  bg [ %job_id]  bg resumes the execution of a suspended job in the background.  If %job_id is omitted the current job is assumed.  bg runs the current or specified jobs in the background.

22-Sep The jobs command  jobs  jobs displays status of suspended and background processes.

22-Sep Suspending a Process  sends a STOP/SUSPEND signal to the current process. The shell displays a message saying that the job has been suspended and displays its prompt.  You can then manipulate the state of this job, put it in the background with the bg command, run some other commands, and then eventually bring the job back into the foreground with the fg command.

22-Sep $ find / -name foo -print 2> /dev/null ^Z [1]+ Stopped find / -name foo -print 2> /dev/null $ bg [1]+ find / -name foo -print 2> /dev/null & $ jobs [1]+ Running find / -name foo -print 2> /dev/null & $ fg find / -name foo -print 2> /dev/null [ command output ] $ Sample Session

22-Sep Terminating Current Process  sends the SIGINT signal to the current process, which, by default, terminates the process. $ find / -name foo -print 1> out 2> /dev/null ^C $

22-Sep Terminating a Process  kill [-signal] PID sends signal number ‘signal’ to process with ID ‘PID’  kill 123 sends the SIGTERM signal to the process with ID 123  kill –9 sends the ‘sure kill’ signal, e.g., kill –

22-Sep Terminating a Process  kill –l displays the signals supported by the system and their numbers $ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE 9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSR1... $

22-Sep Issues with Processes  The fork() system call is expensive  IPC is required to pass information between a parent and its child processes.

22-Sep Thread Concept  A thread is a “lightweight” process which executes within the address space of a process.  A thread can be scheduled to run on a CPU as an independent unit and terminate.  Multiple threads can run simultaneously.

22-Sep Thread Concept  Threads have their own  Thread ID  CPU context (PC, SP, register set, etc.)  Stack  Priority  errno

22-Sep Thread Concept  Threads share  Code and data  Open files (through the PPFDT)  Current working directory  User and group IDs  Signal setups and handlers  PCB

22-Sep Single and Multithreaded Processes

22-Sep Threads are Similar to Processes  A thread can be in states similar to a process (new, ready, running, blocked, terminated)  A thread can create another thread

22-Sep Threads are Different from Processes  Multiple threads can operate within the same address space  No “automatic” protection mechanism is in place for threads—they are meant to help each other

22-Sep Advantages of Threads  Responsiveness  Multi-threaded servers (e.g., browsers) can allow interaction with user while a thread is formulating response to a previous user query (e.g., rendering a web page)

22-Sep Advantages of Threads  Resource sharing  Process resources (code, data, etc.)  OS resources (PCB, PPFDT, etc.)

22-Sep Advantages of Threads  Economy  Take less time to create, schedule, and terminate  Solaris 2: thread creation is 30 times faster than process creation and thread switching is five times faster than process switching

22-Sep Advantages of Threads  Performance in multi-processor and multi-threaded architectures (e.g., Intel’s P4 HT)  Multiple threads can run simultaneously

22-Sep Disadvantages of Threads  Resource sharing— synchronization needed between threads  Difficult to write and debug multi-threaded programs

22-Sep Recap of Lecture User and kernel threads User and kernel threads Pthreads Pthreads Sample code Sample code UNIX/Linux commands/calls: pthread_create, pthread_join, pthread_exit UNIX/Linux commands/calls: pthread_create, pthread_join, pthread_exit