CSE506: Operating Systems CSE 506: Operating Systems

Similar documents
CSE506: Operating Systems CSE 506: Operating Systems

Linux Operating System

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

The Classical OS Model in Unix

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

CS4500/5500 Operating Systems File Systems and Implementations

* What are the different states for a task in an OS?

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

The Operating System. Chapter 6

Address spaces and memory management

CS 326: Operating Systems. Process Execution. Lecture 5

Operating System Structure

Mon Sep 17, 2007 Lecture 3: Process Management

Design Overview of the FreeBSD Kernel CIS 657

Design Overview of the FreeBSD Kernel. Organization of the Kernel. What Code is Machine Independent?

CSE 120 Principles of Operating Systems

Pebbles Kernel Specification September 26, 2004

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Processes. Johan Montelius KTH

What is a Process? Processes and Process Management Details for running a program

UNIX Kernel. UNIX History

A process. the stack

Applications of. Virtual Memory in. OS Design

Lecture 4: Memory Management & The Programming Interface

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

Process Management! Goals of this Lecture!

virtual memory Page 1 CSE 361S Disk Disk

Process Control. Philipp Koehn. 23 April 2018

History of FreeBSD. FreeBSD Kernel Facilities

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Processes. Dr. Yingwu Zhu

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

CS61 Scribe Notes Lecture 18 11/6/14 Fork, Advanced Virtual Memory

CSE 560 Computer Systems Architecture

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

(In columns, of course.)

Project 1: Implementing a Shell

CS240: Programming in C

Creating a Shell or Command Interperter Program CSCI411 Lab

Processes and Exceptions

CS 322 Operating Systems Practice Midterm Questions

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Process Management 1

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

CS 550 Operating Systems Spring Process II

Midterm Exam CPS 210: Operating Systems Spring 2013

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

Processes. CS3026 Operating Systems Lecture 05

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Operating System Labs. Yuanbin Wu

CSE 120 Principles of Operating Systems Spring 2017

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

VEOS high level design. Revision 2.1 NEC

W4118 Operating Systems. Junfeng Yang

CST Algonquin College 2

Section 2: Processes

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

ECE 498 Linux Assembly Language Lecture 1

Unix API Books. Linux Kernel Books. Assignments and Exams. Grading for CSC 256. Operating Systems 8/31/2018. CSC 256/456 Fall

High Performance Computing Lecture 11. Matthew Jacob Indian Institute of Science

3. Process Management in xv6

CS399 New Beginnings. Jonathan Walpole

CPS221 Lecture: Operating System Functions

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

Inter-Process Communication

PROCESS CONTROL: PROCESS CREATION: UNIT-VI PROCESS CONTROL III-II R

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Lecture 1 OS Introduction. Bo 2018, Spring

Basic OS Progamming Abstrac7ons

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Motivation. Operating Systems. File Systems. Outline. Files: The User s Point of View. File System Concepts. Solution? Files!

Basic OS Progamming Abstrac2ons

Virtual Memory Oct. 29, 2002

Process Migration. David Zuercher CS555 Distributed Systems

CS5460: Operating Systems

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

MARUTHI SCHOOL OF BANKING (MSB)

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

Exceptions and Processes

Processes. Operating System Concepts 8 th Edition

Princeton University Computer Science 217: Introduction to Programming Systems Exceptions and Processes

o Reality The CPU switches between each process rapidly (multiprogramming) Only one program is active at a given time

Operating System Review

CSE 451: Operating Systems Winter Processes. Gary Kimura

Problem Set: Processes

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 25

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Transcription:

CSE 506: Operating Systems What Software Expects of the OS

What Software Expects of the OS Shell Memory Address Space for Process System Calls System Services Launching Program Executables

Shell Gives user ability to interact with machine Can be text or graphical Traditionally text-based Two families sh (bash, zsh, ksh) and csh (tcsh) Interprets commands, one by one Commands are either shell built-ins or executables Shells include many user-friendly features PATH env variable, tab completion, Systems start with /etc/rc ( run commands ) Starts with #!/bin/sh

What Software Expects of the OS Shell Memory Address Space for Process System Calls System Services Launching Program Executables

Memory Abstraction CSE506: Operating Systems OS provides memory space to application Application observes a contiguous private memory space OS prevents illegal actions (e.g., no-exec, read-only) Memory typically includes several sections.text program area.rodata read-only variables.data variables that have an initial value.bss variables that are initially zero heap stack

Traditional Memory View CSE506: Operating Systems Don t use addrs. close to 0 Allows to detect bad accesses Heap grows upward Increases when app asks for mem. Stack grows downward Function calls push return addr. Local variables go on stack Main source of stack smash attacks Must reserve stack space Ensure that heap doesn t hit stack #FFFF,FFFF #0000,0000 stack heap bss data rodata program

Modern Memory View CSE506: Operating Systems Heap no longer allocated up Although it still can be Shared libraries appear [vdso] adds magic memory Example: always contains current time #FFFF,FFFF vdso stack libs heap heap bss data rodata #0000,0000 program

What Software Expects of the OS Shell Memory Address Space for Process System Calls System Services Launching Program Executables

System Calls Mechanism for app to interact with the OS Similar to function calls Code securely implemented in the OS Follows predefined interface Called ABI Application Binary Interface Functions referenced by predefined number Example syscall triggers trap instruction Special syscall instruction

getpid() Example System Calls Return process s ID Function 39 in 64-bit Linux, 20 in FreeBSD brk() Return current top of heap Function 12 in 64-bit Linux, 69 in FreeBSD CSE506: Operating Systems Linux has ~650, FreeBSD ~400 syscalls

What Software Expects of the OS Shell, Memory Address Space for Process System Calls System Services Launching Program Executables

Services Provided by OS Usually through syscalls CSE506: Operating Systems Variants: vdso provides time of day, stack grows on faults Typical important services Scheduler Memory management Threads Terminal File system Pipes Network Limits Numerous services exist; we ll stick to the above.

Process Control and Threads (1/2) Create and control processes and threads Same syscall for both in Linux: clone() FreeBSD uses fork() for procs and thr_create() for threads Difference between processes and threads? Fundamentally similar, separate threads of control Threads share same memory space But have their own stack pointers All threads should share one PID, but have own TIDs Exert control over processes kill()/signal() to KILL, TERMinate, STOP, CONTinue

Process Control and Threads (2/2) Create and control processes and threads clone() in Linux, fork() in FreeBSD Creates an identical copy of the process: int pid = fork(); if (pid == 0) { // child code } else if (pid > 0) { // parent code } else { } // error (pid == -1)

Scheduler If there are multiple processes Something has to decide what should run Takes into account many parameters Readiness to run, priority, history Can be invoked by various triggers On syscall called cooperative multi-tasking Low overhead What happens when there are no system calls? On timer called preemptive multi-tasking Processes can get de-scheduled at any time Can still be slightly cooperative by calling yield() syscall

Memory Management Each process sees its own memory space Called virtual memory Computer has DRAM chips plugged into it Called physical memory OS manages physical memory CSE506: Operating Systems Operates on contiguous pages of memory (typically 4KB) Maintains a virtual-to-physical mapping Physical pages are allocated on demand Supports paging (saving physical page contents to disk) Sometimes used interchangeably with swapping (entire apps)

Memory Management Process starts with some memory text, data, stack, heap Stack grows automatically On an access below the stack Allocate up to and including the demanded page Heap grows on request Traditionally, brk(new_value) Modern systems use mmap() malloc() uses one or the other CSE506: Operating Systems Implementations rarely release brk() memory back to the OS

Not the same as console Terminal (1/3) CSE506: Operating Systems Although console is usually connected to a terminal Terminals have two ends One connects to an input/output device Teletype, serial port, console/screen and keyboard Other end attached to software (e.g., bash) Anything written into one end comes out the other Extremely convenient for such a simple interface Provide input discipline Buffers input until newline Handles necessities like local echo

Terminal (2/3) Formatting done via escape sequences CSE506: Operating Systems Sequences of characters control output behavior Example: vt100 family sets red color with: ESC[31m Input also has a level of processing Printable characters pass as-is Modifiers (e.g., Control) used for additional control H is ASCII 40, Ctrl+H is ASCII 8 Backspace key is typically just ASCII 8 C is ASCII 35, Ctrl+C is ASCII 3 Terminal sends SIGINT to foreground process when receiving char 3 Implements type-ahead, buffers chars until they are read

Terminal (3/3) Most systems today use pseudo terminals No physical hardware attached for I/O CSE506: Operating Systems Simulated with network (e.g., ssh) or graphical widow (e.g., xterm) Arranged as pair of devices in OS Traditional software end is slave Traditional teletype is master Things written to slave end come out of master and vice versa Terminals are a fundamental part of the OS Sadly, many people consider them archaic and legacy In truth, a necessary and major modern component

Provides access to data File System open/creat, read, write, seek, close opendir, readdir, closedir, mkdir, unlink mmap (interface combines memory and files) Organized as mount points Each mount point is a directory in the parent system root mount point always at the top OS maintains a descriptor table for each open file Returned by open() Used by all subsequent operations Everyone here must already be familiar with this

Pipes Primitive (but helpful) inter-process communication Enables one process to communicate to another Uni-directional (has distinct writer and reader ends) Uses same interface as files OS maintains descriptors in same table as regular files created with pipe() call (or open() on fifo file type) write/read done just like on files Kernel maintains a small buffer as temp storage Avoids switching between processes after every byte Everyone here must already be familiar with this

Network Enables communication between processes Can be even on same machine (e.g., localhost ) Dominated by IPv4 today Common operations Assign address to an interface Manipulate routing table Make outgoing connections, receive incoming connections Send data, receive data Uses same descriptor table as files Called socket descriptors for network Everyone should already be familiar with this

Limits OS protects processes from each other And processes from themselves Parent process limits are inherited by child process Process can set its own limits Can set hard limits lower or equal to existing ones Can only reduce, can never increase Can set soft limits lower or equal to hard ones Examples: These are the actual limits enforced by the OS Max memory, max stack size, max open files Some limits are per user e.g., number of processes

What Software Expects of the OS Shell Memory Address Space for Process System Calls System Services Launching Program Executables

Launching Program Executables (1/2) Roughly a 3-step process Load initial contents into memory Find starting point (usually function called _start()) Set initial registers (stack pointer, program counter) How to load program into memory? Dictated by binary format Most systems today use ELF or PE Defines parts of the file to load and where to load tem Broken up into sections Offset (in the file), length, destination address, and size Length can be smaller than size indicates zero pad

Launching Program Executables (2/2) Programs are launched using execve syscall First bytes determine binary format 0x7F E L F : ELF binary #!command : (shebang) interpret with (command) An interpreter may run instead of the program Program becomes first argument to interpreter Interpreter path supported in ELF binaries Critical for shared libraries Interpreter is set to /lib/ld.so for instance Running /bin/ls / is equivalent to /libexec/ld-elf.so /bin/ls /