Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Chapter 3 Process Description and Control
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
6/9/2015B.Ramamurthy1 Process Description and Control B.Ramamurthy.
Process Description and Control
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
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.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Process Concept An operating system executes a variety of programs
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
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.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
PROCESSES TANNENBAUM, SECTION 2-1 OPERATING SYSTEMS.
Chapter 3 Process Description and Control
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Threads G.Anuradha (Reference : William Stallings)
Computer Studies (AL) Operating System Process Management - Process.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Processes Questions answered in this lecture: What is a process? How does the dispatcher context-switch between processes? How does the OS create a new.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
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.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Processes & Threads Introduction to Operating Systems: Module 5.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Processes 2 Introduction to Operating Systems: Module 4.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
OPERATING SYSTEMS CS3502 Fall 2017
Protection of System Resources
Operating Systems: A Modern Perspective, Chapter 6
System Structure and Process Model
System Structure and Process Model
Structure of Processes
System Structure B. Ramamurthy.
CS 143A Quiz 1 Solution.
System Structure and Process Model
Process & its States Lecture 5.
Mid Term review CSC345.
Process Description and Control
Process Description and Control
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Process Description and Control
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
Process Description and Control
Process Description and Control in Unix
Process Description and Control in Unix
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Processes, Threads, and Process States

Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program that is active in the system  A program can be written to activate new processes  Two important issues about processes  Process Control Block (PCB)  Process states  During execution, the process can be in one of the several states  Ready, running, blocked, etc.

Processes Control Block (PCB)  PCB: A record used by the OS to keep track of the information related to a process  What information is needed?  About the process itself  Process id  Execution priority  Accounting: resource usage (like how much CPU time used, etc.)  What else?  How about context switch  Need space to store contents of the registers  The information is in PCB  What else?

Processes Control Block (PCB)  What else?  To execute a program, what is being used?  Memory, I/O devices, files  PCB keeps pointers to  Memory segments (pages) in use  Files opened –File descriptors  I/O information –Sockets opened –Other I/O device such as monitor, keyboard, etc.

Process States  During execution, the process can be in one of the 7 states (7 state model) Ne w Admit Suspend Dispatch Time out Ready, suspend Ready Blocked Blocked, suspend Event Occurs Activate Event Occurs Activate Suspend Running Exit Event Wait When you run a program, a new process is created If the system has sufficient memory, then the new process is loaded into memory and placed in ready queue Otherwise, ready suspend CPU scheduler takes a process from the head of the ready queue to execute (Sometimes, there may be multiple ready queues.) (We will cover CPU scheduling later.) If processes are scheduled in a round robin manner, then when time quantum expires, the process is returned to ready queue After finish execution, exit Process may be blocked by: - I/O (wait for I/O to complete) - semaphore wait - sleep - etc. When the waiting is over  An interrupt is generated  Process is then returned to ready queue When the system runs low on memory, a process may be swapped out and goes into the suspend state - If from blocked state, then blocked suspend - If from ready state, then ready suspend Once it is OK to bring the process back, then the process gets swapped in and returns to wherever it was A process can run in - User mode: regular program execution - Kernel mode: OS is running - due to a system call - due to an interrupt (running interrupt handler)

Process States Ne w Admit Suspend Dispatch Time out Ready, suspend Ready Blocked Blocked, suspend Event Occurs Activate Event Occurs Activate Suspend Running Exit Event Wait

When you run a program, a new process is created If the system has sufficient memory, then the new process is loaded into memory and placed in ready queue Otherwise, ready suspend CPU scheduler takes a process from the head of the ready queue to execute (Sometimes, there may be multiple ready queues.) (We will cover CPU scheduling later.) If processes are scheduled in a round robin manner, then when time quantum expires, the process is returned to ready queue After finish execution, exit Process may be blocked by: - I/O (wait for I/O to complete) - semaphore wait - sleep - etc. When the waiting is over  An interrupt is generated  Process is then returned to ready queue

When the system runs low on memory, a process may be swapped out and goes into the suspend state - If from blocked state, then blocked suspend - If from ready state, then ready suspend Once it is OK to bring the process back, then the process gets swapped in and returns to wherever it was A process can run in - User mode: regular program execution - Kernel mode: OS is running - due to a system call - due to an interrupt (running interrupt handler)

Process State Transition  When process state changes  The PCB will be moved to the associated queues  Some state transitions result in process switch  E.g., time quantum expiration, process gets blocked  Example of process state changes

Processes and Threads  A process is a unit of  Resource ownership (address space, I/O devices, files, etc.)  E.g., each process has its own address space  Dispatching (process state)  Thread is a only a unit of  Dispatching  Not for resource ownership  It is a light-weight process  A process may create several processes  Each of them has its own address space  A process may create several threads  All of them share the same address space

Processes  Unix process creation main() { int pid; printf (“before fork”); pid = fork(); if (pid == 0) printf (“child process”); else printf (“parent process”); } a=1; b=3; ab parent address space 13 child address space After fork, an exact copy is made a=2; b=4; 2456 a=5; b=6; Parent and child each change on their own address space

Processes and Threads  Unix process creation main() { int pid; printf (“before fork”); pid = fork(); if (pid == 0) printf (“child process”); else printf (“parent process”); } a=1; b=3;... ab parent address space pid child address space 13 After fork - parent process gets child pid (needed if parent needs to wait for child to finish) - child process gets pid = 0 x 0

Threads  A thread is a unit for dispatching  Need to have a thread control block (TCB)  What is needed in TCB  Thread id, thread privilege information  Execution stack  Pointer to the tables of the parent process  Creation overhead comparison  fork(): 1700 usec  thread: 52 µsec (if no OS involvement)  Much cheaper to create a thread or perform thread switch  (Old data based on Sparc-2)

Threads  A thread does not have its own address space  Thread created by one process share the address space of the process... ab parent thread 13 child thread address space of the parent process

Thread Implementation  What should be provided to the user  Mechanisms for thread creation and disposal  Mechanisms for handling sharing  E.g., semaphors or monitors to synchronize memory accesses  Thread library could be implemented at the  User level (not visible to OS)  Kernel level (visible to OS)  Advantages of user-level thread library  Lower cost  No kernel trap required for thread switch  Still need context switch  Flexible, customized thread scheduling

Thread Implementation  Disadvantages of user-level thread library  Harder to manipulate  When a thread is blocked (e.g., read, sleep), the entire program is blocked  Actually, another thread could execute and make use of the time quantum  Solution: –Block the thread at the thread level and switch to another thread –The system call that causes blocking should be modified so that the program does not get blocked –The thread should not be scheduled to run till the condition is satisfied (e.g., read is completed, sleep time is up) –When threads block often, this solution can be more expensive

Thread Implementation  Disadvantages of user-level thread library  Hard to do round-robin type of scheduling  Due to the lack of timer at the program level  Set timer involves a kernel trap and time-out involves a kernel interrupt

Readings  Section  Section 4.1  Only the part about user level thread and kernel level thread