Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.

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

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.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
CSCE 351: Operating System Kernels
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.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Process Description and Control A process is sometimes called a task, it is a program in execution.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
System Calls 1.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
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.
Implementing Processes and Process Management Brian Bershad.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
1 Lecture 4: Threads Advanced Operating System Fall 2010.
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.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
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 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
Intro to Processes CSSE 332 Operating Systems
Processes in Unix, Linux, and Windows
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
System Structure and Process Model
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Process Description and Control
Lecture Topics: 11/1 General Operating System Concepts Processes
Processes Hank Levy 1.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Process Description and Control in Unix
CSE 153 Design of Operating Systems Winter 2019
Processes Hank Levy 1.
Presentation transcript:

Processes CS 6560: Operating Systems Design

2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode instruction Execute instruction CPU Memory

3 Image of Executing Program Memory PC: 100 CPU 100load R1, R2 104add R1, 4, R1 108load R1, R3 112add R2, R3, R3 … R1: 2000 R2: R3:

4 How Do We Write Programs Now? How to map a program like this to a Von Neuman machine? Where to keep yv, nv? What about foo_obj and tyv? How to do foo->cheat()? public class foo { static private int yv = 0; static private int nv = 0; public static void main() { foo foo_obj = new foo; foo_obj->cheat(); } public cheat() { int tyv = yv; yv = yv + 1; if (tyv < 10) { cheat(); }

5 Global Variables Dealing with “global” variables like yv and nv is easy Let’s just allocate some space in memory for them This is done by the compiler at compile time A reference to yv is then just an access to yv’s location in memory Suppose yv is stored at location 2000 Then, yv = yv + 1 might be compiled to something like loadi2000, R1 loadR1, R2 addR2, 1, R2 storeR1, R2

6 Local Variables What about foo_obj defined in main() and tyv defined in cheat()? 1st option you might think of is just to allocate some space in memory for these variables as well (as shown to the right) What is the problem with this approach? How can we deal with this problem? yv nv foo_obj tyv 2008

7 Local Variable Allocate a new memory location to tyv every time cheat() is called at run-time Convention is to allocate storage in a stack (often called the control stack) Pop stack when returning from a method: storage is no longer needed Code for allocating/deallocating space on the stack is generated by compiler at compile time foo->cheat(); tyv = yv; … foo->cheat(); tyv = yv; … tyv tyv’ yv tyv’’ stack globals

8 What About “new” Objects? foo foo_obj = new foo; foo_obj is really a pointer to a foo object As just explained, a memory location is allocated for foo_obj from the stack whenever main() is invoked Where does the object created by the “new foo” actually live? Is the stack an appropriate place to keep this object? Why not?

9 Memory Image Suppose we have executed the following: yv = 0 nv = 0 main() foo_obj = new foo foo->cheat() tyv = yv yv = yv + 1 foo->cheat() tyv = yv yv = yv + 1 foo->cheat() tyv = yv yv = yv + 1 tyv tyv’ yv tyv’’ stack globals foo_obj heap

10 Data Access How to find data allocated dynamically on the stack? By convention, designate one register as the stack pointer Stack pointer always points to current activation record Stack pointer is set at entry to a method Code for setting stack pointer is generated by the compiler Local variables and parameters are referenced as offsets from sp PC SP CPU tyv activation record for cheat()

11 Data Access The statement tyv = tyv + 1 Would then translate into something like addi0, sp, R1# tyv is the only variable so offset is 0 loadR1, R2 addi1, R2 storeR1, R2

12 Local variables Activation Record We have only talked about allocation of local variables on the stack The activation record is also used to store: Parameters A pointer to the beginning of the previous activation record The return address … Other stuff

13 Run Time Storage Organization Each variable must be assigned a storage class Global (static) variables Allocated in globals region at compile-time Routine local variables and parameters Allocated dynamically on stack Dynamically created objects (using new/malloc) Allocated from heap Objects live beyond invocation of a routine Garbage collected when no longer “live” Code Globals Heap Stack Memory

14 Why Did We Talk About All That Stuff? Process = system abstraction for the set of resources required for executing a program = a running instance of a program = memory image + registers’ content (+ I/O state) The stack + registers’ content represent the execution context or thread of control

15 What About The OS? Recall that one of the functions of an OS is to provide a virtual machine interface that makes programming the machine easier So, a process memory image must also contain the OS OS Code Globals Heap Stack Memory Code Globals Heap Stack OS data space is used to store things like file descriptors for files being accessed by the process, status of I/O devices, etc.

16 What Happens In Physical Memory When There is More Than One Running Process? OS Code Globals Heap Stack P0 P1 P2

17 Process Control Block Each process has per-process state maintained by the OS Identification: process, parent process, user, group, etc. Execution contexts: threads Address space: virtual memory I/O state: file handles (file system), communication endpoints (network), etc. Accounting information For each process, this state is maintained in a process control block (PCB) This is just data in the OS data space Think of it as objects of a class

18 Process Creation How to create a process? System call. In UNIX, a process can create another process using the fork() system call int pid = fork();/* this is in C */ The creating process is called the parent and the new process is called the child The child process is created as a copy of the parent process (process image and process control structure) except for the identification and scheduling state Parent and child processes run in two different address spaces By default, there’s no memory sharing Process creation is expensive because of this copying The exec() call is provided for the newly created process to run a different program than that of the parent

19 Process Creation fork() fork() code; exec() code exec() PCBs

20 Example of Process Creation Using Fork The UNIX shell is a command-line interpreter whose basic purpose is for the user to run applications on a UNIX system cmd arg1 arg2... argn

21 Process Death (or Murder) One process can wait for another process to finish using the wait() system call Can wait for a child to finish as shown in the example Can also wait for an arbitrary process if know its PID Can kill another process using the kill() system call What happens when kill() is invoked? What if the victim process doesn’t want to die?

22 A Tree of Processes On A Typical UNIX System

23 Signals User program can invoke OS services by using system calls What if the program wants the OS to notify it asynchronously when some event occurs? Signals UNIX mechanism for OS to notify a user program when an event of interest occurs Potentially interesting events are predefined: e.g., segmentation violation, message arrival, kill, etc. When interested in “handling” a particular event (signal), a process indicates its interest to the OS and gives the OS a procedure that should be invoked in the upcall How does a process indicate its interest in handling a signal?

24 Signals (Cont’d) When an event of interest occurs: The kernel handles the event first, then modifies the process’s stack to look as if the process’s code made a procedure call to the signal handler. Puts an activation record on the user- level stack corresponding to the event handler When the user process is scheduled next it executes the handler first From the handler, the user process returns to where it was when the event occurred A B A B Handler

25 Process: Summary An “instantiation” of a program System abstraction: the set of resources required for executing a program Execution context(s) Address space File handles, communication endpoints, etc. Historically, all of the above “lumped” into a single abstraction More recently, split into several abstractions Threads, address space, protection domain, etc. OS process management: Supports user creation of processes and inter-process communication (IPC) Allocates resources to processes according to specific policies Interleaves the execution of multiple processes to increase system utilization

26 Next Time Threads