CSCE 313 – Introduction to UNIx process

Slides:



Advertisements
Similar presentations
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
Advertisements

1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Introduction to Kernel
OS Spring’03 Introduction Operating Systems Spring 2003.
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Computer Organization and Architecture
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
OS Spring’04 Introduction Operating Systems Spring 2004.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
System Calls 1.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Protection and the Kernel: Mode, Space, and Context.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) 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.
VIRTUAL MEMORY By Thi Nguyen. Motivation  In early time, the main memory was not large enough to store and execute complex program as higher level languages.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Processes and Virtual Memory
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.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
Operating Systems: Summary INF1060: Introduction to Operating Systems and Data Communication.
Memory Management Chapter 5 Advanced Operating System.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Introduction to Operating Systems Concepts
Computer Organization & Design 计算机组成与设计
Introduction to Kernel
Introduction to Operating Systems
Processes and threads.
CE 454 Computer Architecture
Chapter 2 Memory and process management
CSE 120 Principles of Operating
CS 6560: Operating Systems Design
Outline Paging Swapping and demand paging Virtual memory.
Chapter 9: Virtual Memory
Modeling Page Replacement Algorithms
William Stallings Computer Organization and Architecture
CS 3305 System Calls Lecture 7.
Chapter 4 Threads.
Swapping Segmented paging allows us to have non-contiguous allocations
CSE 153 Design of Operating Systems Winter 2018
Lecture 28: Virtual Memory-Address Translation
Introduction to Operating Systems
O.S Lecture 13 Virtual Memory.
HW & Systems: Operating Systems IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, October 22, 2013 Carolyn Seaman University of Maryland, Baltimore.
So far… Text RO …. printf() RW link printf Linking, loading
CS399 New Beginnings Jonathan Walpole.
Process & its States Lecture 5.
Modeling Page Replacement Algorithms
Operating Systems.
Exceptions Control Flow
Threads Chapter 4.
CSE 451: Operating Systems Autumn 2005 Memory Management
CS201 - Lecture 17 Exceptions
Operating System Chapter 7. Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Operating Systems: A Modern Perspective, Chapter 6
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Mechanism: Address Translation
Virtual Memory and Paging
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

CSCE 313 – Introduction to UNIx process Reading Reference: Textbook 1 Chapter 2 CSCE 313 – Introduction to UNIx process Tanzir Ahmed CSCE 313 Fall 2018

Outline Process Definition API Introduction Processor Virtualization Concurrent Processes Context Switching Memory Virtualization Address Space Virtual Memory Page Faults 1/14/2019

Running Programs in a Computer “How does Unix run programs? It looks easy enough: you log in, your shell prints a prompt, you type a command and press Enter. Soon a program runs. When the program finishes, your shell prints a new prompt. How does that work? ” The same goes for running a program on Windows (or any other OS), either by double-clicking or typing the name in the command prompt * Understanding Linux/Unix Programming, by Bruce Molay 1/14/2019

Main Problems Problem # 1: A Computer Program is merely a set of instruction residing in the disk as a file. How to bring this to life? In other words, how to associate the resources to the instructions in the program? Problem # 2: How to run many programs seamlessly in a computer that has a single (or a few) processor(s) IOW, “How do all programs share the same h/w?” Example: Your laptop running hundreds of applications (e.g., the browser, music player, document processor, a real-time game). Each program better be oblivious/independent of other running programs so that it is easy to write programs

Process Definition Process is an instance of a running programming. This happens through its Abstraction Also defined as “A Program in Action” Provided by the OS and used by the program Solves the problems just mentioned To the program, Process is a view of the entire system – memory, CPU, disk and all I/O devices Whatever the program needs, Process has it This view of the system is also called machine state Process is an abstraction, because the program thinks it is the only program running

Process Abstraction A program now makes a request to the OS instead of directly running Because OS is in charge, not the program itself For Process abstraction, OS provides API for the following functionalities: Create/Destroy a process Run a process Stop/Resume a process Query status (we will see a Process can be in many states) A few other important controls and wait functions (for synchronization) We will learn (in a few lectures) how to use some of these in C/C++ language Other languages have very similar-looking API functions

Abstraction Mechanism Process provides each program with two key abstractions: Logical control flow for CPU virtualization Each program seems to have exclusive use of the CPU Private address space for Memory virtualization Each program seems to have exclusive use of main memory How are these illusions maintained? Process executions interleaved (multitasking) Private address spaces managed by virtual memory system (will describe that in a bit) 1/14/2019

Logical Control Flows Each process has its own logical control flow, which can be far from reality logical control flow actual control flow Time Process A Process B Process C Time Process A Process B Process C Control flows for concurrent processes are physically disjoint in time (except on multi-core machines) However, we can think of concurrent processes as running in ‘parallel’ with each other 1/14/2019

Context Switching Control flow passes from one process to another via a context switch Has to store the Process state in a way so that it can be retrieved later exactly where it was left off (not from the start) We will see the mechanism of context switch in more details in a little bit. However, the main steps are these: Store the current process’s stat. This is done by CS code in OS Invoke the scheduler that will pick another process Load that other process into the CPU. Again, done by CS code in OS Process A code Process B code user code context switch OS code Time user code OS code context switch user code 1/14/2019

Process Image in Physical Memory In reality, this is how* processes look in physical memory: 1/14/2019 * A very simplified view, ignoring fragmentation completely

Private Address Space Illusion But each process is made to believe that the memory looks like the following – thanks to Virtual Memory: How big can this be? memory mapped region for shared libraries run-time heap (managed by malloc) user stack (created at runtime) Kernel %esp (stack pointer) brk 0xffffffff 0x08048000 0x40000000 read/write segment (.data, .bss) read-only segment (.init, .text, .rodata) loaded from the executable file Depends on machine architecture. For a 32 bit machine 232 = 4GB For a 64 bit machine 264 = 16EB 1/14/2019

Question Is a process image really 232 = 4GB long? It would be nice for us, programmers But typically, physical memory is quite limited Virtual memory in action What is then Virtual Memory? For that, we now need to a little understanding on how memory is organized in a system 1/14/2019

Memory Organization Memory is logically divided into pages, which are fixed in size and aligned regions of memory Typical size: 4KB/page But pages are associated to a process only when necessary (i.e., read or written) When not necessary, they are evicted to the disk Thus a running process can be stored back to disk again!!!! The mechanism of such lazy-allocation is through Page Fault If a non-existent page is accessed (R/W), a page fault happens and fault-handler allocates the required page in physical memory 0-4095 4096-8191 8192-12287 12288-16383 … Page 0 Page 1 Page 2 Page 3 4KB 8KB 12KB 1/14/2019

Mapping from Virtual to Physical Memory Virtual Memory Physical Memory Virtual Memory Page Table Page Table 0K Page 0 Frame 0 Page 0 4K 4K 4K Page 1 Frame 1 Page 1 8K 8K 8K Frame 2 Page 2 12K 12K Frame 3 16K Frame 4 Private to Process #1 Of Process #2 264 264 1/14/2019

Summarizing Virtual Memory The private address space of a process is made up of pages These pages can be spread according to the wish of the kernel Contiguous memory in processes’ view are not necessarily contiguous in physical memory – they can be physically scattered, but stitched together by Virtual Memory system Because memory scarce, the whole private address space does not need to be allocated all the time: Actual pages can be allocated/mapped only when needed (i.e., read or written) through page faults Even allocated but inactive pages can be swapped back to disk to make room for more active pages Memory accessed is further slowed down by Page Table access Each address must be translated to physical address by looking up in the process’s page table, which is also in memory Thus each memory access is actually 2 memory accesses: 1 for page table, another for the actual memory access 1/14/2019