Operating Systems: A Modern Perspective, Chapter 6

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

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.
Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources.
Processes CSCI 444/544 Operating Systems Fall 2008.
Process Management. External View of the OS Hardware fork() CreateProcess() CreateThread() close() CloseHandle() sleep() semctl() signal() SetWaitableTimer()
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.
Chapter 6 Implementing Processes, Threads, and Resources.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6.
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Implementing Processes and Process Management Brian Bershad.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
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.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources 6.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
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.
2 Processor(s)Main MemoryDevices Process, Thread & Resource Manager Memory Manager Device Manager File Manager.
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 a Process ? A program in execution.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Lecture 3 Process.
Processes and threads.
Process concept.
Operating Systems CMPSC 473
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Operating Systems (CS 340 D)
Lecture Topics: 11/1 Processes Process Management
Process Management Presented By Aditya Gupta Assistant Professor
Implementing Processes and Threads
Overview of today’s lecture
Chapter 3: Process Concept
Operating Systems: A Modern Perspective, Chapter 6
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Operating Systems (CS 340 D)
COP 4600 Operating Systems Fall 2010
Process Virtualization. Process Process is a program that has initiated its execution. A program is a passive entity; whereas a process is an active entity.
Process management Information maintained by OS for process management
CGS 3763 Operating Systems Concepts Spring 2013
Lecture 2: Processes Part 1
Threads, SMP, and Microkernels
Process & its States Lecture 5.
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 4.
Processes Hank Levy 1.
Processes and Process Management
Chapter 3: Processes.
Implementing Processes and Threads
Implementing Processes, Threads, and Resources
CS510 Operating System Foundations
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Outline Process Management Process manager Hardware process
CSE 153 Design of Operating Systems Winter 2019
Processes Hank Levy 1.
Implementing Processes, Threads, and Resources
Chapter 3: Process Concept
Presentation transcript:

Operating Systems: A Modern Perspective, Chapter 6 Processes Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 Announcements Extension til Friday 11 am for HW #1 Previous lectures online Program Assignment #1 online later today, due 2 weeks from today Homework Set #2 online later today, due a week from today Read chapter 6 Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 What is a Process? Program P1 A software program consist of a sequence of code instructions and data for now, let a simple app = a program CPU executes the instructions line by line in fetch-execute cycle from RAM code instructions operate on data A program is a passive entity A process is a program actively executing from main memory Code Data Operating Systems: A Modern Perspective, Chapter 6

Loading and Executing a Program Process Code Data Main Memory OS Loader Program P1 binary CPU Execution Program Counter (PC) Registers ALU Fetch Code and Data Write Data Disk Code Data P1 binary P2 Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 What is a Process? A process is a program actively executing from main memory has a Program Counter (PC) and execution state associated with it CPU registers keep state OS keeps process state in memory it’s alive! has an address space associated with it a limited set of (virtual) addresses that can be accessed by the executing code Main Memory Process CPU Execution Program Counter (PC) Registers ALU Fetch Code and Data Write Data Program P1 binary Code Data Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 What is a Process? Main Memory Process 2 processes may execute the same program code, but they are considered separate execution sequences CPU Execution Program Counter (PC) Registers ALU Fetch Code and Data Write Data Program P1 binary Code Data Operating Systems: A Modern Perspective, Chapter 6

How is a Process Structured in Memory? Main Memory float f4=3.0; main() { char* ptr; ptr = malloc(); foo1(); } foo1() { int a1; .... global variables functions local variables dynamically allocated variables Process P1 Code Data Operating Systems: A Modern Perspective, Chapter 6

How is a Process Structured in Memory? Main Memory float f4=3.0; main() { char* ptr; ptr = malloc(); foo1(); } foo1() { int a1; .... global variables functions local variables dynamically allocated variables Process P1 Code Data Heap Stack Operating Systems: A Modern Perspective, Chapter 6

How is a Process Structured in Memory? Run-time memory max address User stack Run-time memory image Essentially code, data, stack, and heap Code and data loaded from executable file Stack grows downward, heap grows upward Unallocated Heap Read/write .data, .bss Read-only .init, .text, .rodata address 0 Operating Systems: A Modern Perspective, Chapter 6

Why Allocate Local Variables on a Stack? Strawman approach: pre-allocate all local variables a priori before a process starts executing, just like global variables What’s wrong with this strawman? if a function is never called, then you’ve wasted space allocating its local variables don’t know a priori how many instances of a local variable to allocate if a function calls itself, i.e. recursion Operating Systems: A Modern Perspective, Chapter 6

Why Allocate Local Variables on a Stack? So allocate local variables only on an as-needed basis A stack provides a simple way to allocate local variables as needed When a function is called, allocate its local variables on top of the stack - push them on the stack when a function completes, deallocate these local variables - pop them off the stack Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 Why Allocate Dynamic Variables on a Heap in the Process’s Address Space? Strawman II: could ask the OS to allocate dynamic variables anywhere in memory very complex keeping tracking of all the different locations in memory Keeping the dynamic variables in one area (the process’s heap) associated with the process’s address space simplifies memory management Operating Systems: A Modern Perspective, Chapter 6

A Process Executes in its Own Address Space Main Memory OS tries to provide the illusion or abstraction that the process executes in its own address space, on its own CPU Process P1 Code Data Heap Stack Operating Systems: A Modern Perspective, Chapter 6

Implementing the Process Abstraction Pi Address Space Pi CPU Pi Executable Memory Pj Address Space Pj CPU Pj Executable Memory Pk Address Space … Pk CPU Pk Executable Memory OS interface OS Address Space CPU ALU Machine Executable Memory Control Unit … Operating Systems: A Modern Perspective, Chapter 6

OS Process Management: External View Application Process Device Mgr Process Mgr Memory Mgr File Mgr Windows CreateThread() CreateProcess() CloseHandle() WaitForSingleObject() fork() wait() exec() Device Mgr Process Mgr Memory Mgr File Mgr UNIX Hardware Operating Systems: A Modern Perspective, Chapter 6

Process Manager Responsibilities Define & implement the essential characteristics of a process and thread Algorithms to define the behavior Data structures to preserve the state of the execution Define what “things” threads in the process can reference – the address space (most of the “things” are memory locations) Manage the resources used by the processes/threads Tools to create/destroy/manipulate processes & threads Tools to time-multiplex the CPU – Scheduling the (Chapter 7) Tools to allow threads to synchronization the operation with one another (Chapters 8-9) Mechanisms to handle deadlock (Chapter 10) Mechanisms to handle protection (Chapter 14) Operating Systems: A Modern Perspective, Chapter 6

Process Manager Overview Program Process Abstract Computing Environment Deadlock Process Description File Manager Protection Synchronization Device Manager Memory Manager Resource Manager Scheduler Devices Memory CPU Other H/W Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 OS Process Management Main Memory OS keeps a Process Control Block (PCB) for each process: Process state: new, running, waiting, ready, terminated Program counter CPU registers CPU-scheduling information, e.g. priority memory management info: value of base and limit registers, page tables, segment tables I/O info: open files, etc. Process P1 Code Data Heap Stack Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 Multiple Processes Main Memory Each process is in memory Only one process at a time executes on the CPU OS provides the mechanisms to switch between processes this is called a context switch Code Data Process P1 Heap Stack Process P2 Code Data Heap Stack Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 Context Switching Executable Memory Each time a process is switched out, its context must be saved, e.g. in the PCB Each time a process is switched in, its context is restored This usually requires copying of registers Initialization 1 Process Manager 9 6 4 2 5 8 3 7 Interrupt Interrupt Handler P1 P2 Pn Operating Systems: A Modern Perspective, Chapter 6

Operating Systems: A Modern Perspective, Chapter 6 Context Switches A context switch can occur because of a system call an I/O interrupt, e.g. disk has finished reading a timer interrupt this is how you implement multitasking Set a timer in the CPU for periodic interrupt, say every 1 ms On an interrupt, go to the timer interrupt handler, e.g. the scheduler, and switch to another process in the ready queue Context switch time is pure overhead it is the price you pay for multiprogramming typically a few milliseconds Operating Systems: A Modern Perspective, Chapter 6

Multiple Processes: State Diagram Request Done Running Request Schedule Start Allocate Blocked Ready Operating Systems: A Modern Perspective, Chapter 6

Communicating Between Processes Inter-Process Communication or IPC would like two processes to share information between them shared file split a single application into multiple processes to speed up execution by allowing overlapped I/O split an application into multiple processes for modularity of coding if address spaces are completely isolated from one another, then how do we share data? Operating Systems: A Modern Perspective, Chapter 6

Communicating Between Processes Two types of IPC shared memory - OS provides mechanisms that allow creation of a shared memory buffer between processes shmget() creates a shared memory segment, using a name (key ID) shmctl() to modify control information and permissions related to a shared memory segment shmat() to attach a shared memory segment to a process’s address space allows fast and high volume reading/writing of buffer in memory applies to processes on the same machine message passing - OS provides constructs that allow communication via buffers typically implemented via system calls, and is hence slower than shared memory sending process has a buffer to send/receive messages, as does the receiving process used to pass small messages extends to communicating between processes on different machines Operating Systems: A Modern Perspective, Chapter 6

Communicating Between Processes Shared access to the same memory introduces complexity need to synchronize access Producer-Consumer example if two producers write at the same time to shared memory, then they can overwrite each other’s data if a producer writes while a consumer is reading, then the consumer may read inconsistent data Operating Systems: A Modern Perspective, Chapter 6