Recitation 8: Tshlab + VM

Similar documents
Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Recitation 8 Processes, Signals, Tshlab

Recitation Processes, Signals,UNIX error handling

CSC209H Lecture 6. Dan Zingaro. February 11, 2015

UNIX System Calls. Sys Calls versus Library Func

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Process Creation in UNIX

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

everything is a file main.c a.out /dev/sda1 /dev/tty2 /proc/cpuinfo file descriptor int

File Descriptors and Piping

Operating systems. Lecture 7

Operating System Labs. Yuanbin Wu

File I/0. Advanced Programming in the UNIX Environment

CSE 333 SECTION 3. POSIX I/O Functions

CS 25200: Systems Programming. Lecture 14: Files, Fork, and Pipes

CMSC 216 Introduction to Computer Systems Lecture 17 Process Control and System-Level I/O

CMPS 105 Systems Programming. Prof. Darrell Long E2.371

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

Outline. Relationship between file descriptors and open files

15-213: Final Exam Review

CSE 333 SECTION 3. POSIX I/O Functions

Lecture files in /home/hwang/cs375/lecture05 on csserver.

Process Management! Goals of this Lecture!

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING SOFTWARE ENGINEERING DEPARTMENT

Systems Programming. COSC Software Tools. Systems Programming. High-Level vs. Low-Level. High-Level vs. Low-Level.

15-213/18-243, Spring 2011 Exam 2

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

Goals of this Lecture

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

I/O Management! Goals of this Lecture!

I/O Management! Goals of this Lecture!

Preview. System Call. System Call. System Call. System Call. Library Functions 9/20/2018. System Call

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS]

Files. Eric McCreath

The bigger picture. File systems. User space operations. What s a file. A file system is the user space implementation of persistent storage.

UNIX System Programming

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Operating Systems, 142

CS240: Programming in C

628 Lecture Notes Week 4

Topics. Unix Pipes (CSE 422S) In A Nutshell. Ken Wong Washington University. Pipe (Unnamed FIFO) in the Shell.

File Systems. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

OPERATING SYSTEMS: Lesson 2: Operating System Services

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)

Logistics. Recitation 11: I/O Problems. Today s Plan. Why Use Robust I/O. Andrew Faulring Section A 18 November 2002

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Operating System Labs. Yuanbin Wu

15213 Recitation Section C

FILE SYSTEMS. Jo, Heeseung

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Basic OS Progamming Abstrac2ons

CSE 410: Systems Programming

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Basic OS Progamming Abstrac7ons

Pipelines, Forks, and Shell

Section 3: File I/O, JSON, Generics. Meghan Cowan

CS Operating Systems Lab 3: UNIX Processes

Unix File and I/O. Outline. Storing Information. File Systems. (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu

ESE 333 Real-Time Operating Systems 2 What is an operating system? Two views: 1. Top-down view: Extended machine ffl Covers the details of the hardwar

File Systems Overview. Jin-Soo Kim ( Computer Systems Laboratory Sungkyunkwan University

Can Great Programmers Be Taught? Experiences with a Software Design Class. John Ousterhout Stanford University

Advanced Unix/Linux System Program. Instructor: William W.Y. Hsu

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

Lecture 23: System-Level I/O

CSE 410: Systems Programming

Inter-Process Communication

System Calls and Signals: Communication with the OS. System Call. strace./hello. Kernel. Context Switch

Figure 1 Ring Structures

CSE 333 Midterm Exam 2/12/16. Name UW ID#

Virtual Memory: Systems

CS167 Programming Assignment 1: Shell

System- Level I/O. Andrew Case. Slides adapted from Jinyang Li, Randy Bryant and Dave O Hallaron

Introduction to File Systems. CSE 120 Winter 2001

Processes. Processes (cont d)

W4118: OS Overview. Junfeng Yang

Chapter 3 Processes we will completely ignore threads today

System Programming. Pipes I

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

CSC 271 Software I: Utilities and Internals

The Shell, System Calls, Processes, and Basic Inter-Process Communication

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

CSCI 237 Sample Final Exam

System Calls and I/O Appendix. Copyright : University of Illinois CS 241 Staff 1

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 2 November 14, 2014

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 2 November 14, 2014

UNIX System Programming. Overview. 1. A UNIX System. 2. Processes (review) 2.1. Context. Pipes/FIFOs

CSC209H Lecture 7. Dan Zingaro. February 25, 2015

CS 33. Shells and Files. CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 201. Files and I/O. Gerson Robboy Portland State University

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018.

ECE 650 Systems Programming & Engineering. Spring 2018

Process Management 1

Project 2--User Programs

CS , Spring 2009 Exam 2

Transcription:

Recitation 8: Tshlab + VM Instructor: TAs 1

Outline Labs Signals IO Virtual Memory 2

TshLab and MallocLab TshLab due Tuesday MallocLab is released immediately after Start early Do the checkpoint first, don t immediately go for the final Expect a bootcamp and recitation next week Working for several hours will improve their value significantly 3

Signals Parent process sends SIGINT to a child process. What is the behavior of the child? What is the default? What else could the child do? 4

More Signals Parent process sends SIGKILL to a child process. What is the behavior of the child? What is the default? What else could the child do? 5

Sending Signals Parent sends SIGKILL to a child process.... pid_t pid =...; // child pid kill(pid, SIGKILL); // At this point, what has happened // to the child process? 6

Signals How many times is Hi printed? int main(int argc, char** argv) { pid_t ppid = getpid(), cpid, tpid; cpid = fork(); if (cpid == 0) tpid = ppid; else tpid = cpid; kill(tpid, SIGINT); write(stdout_fileno, Hi, strlen( Hi )); return 0; } 7

Blocking Signals The shell is currently running its handler for SIGCHLD. What signals can it receive? What signals can it not receive (i.e., blocked)? 8

Errno Included from <errno.h> Global integer variable usually 0 When a system call fails (usually indicated by returning -1), it also will set errno to a value describing what went wrong Example: let s assume there is no foo.txt in our path int fd = open( foo.txt, O_RDONLY); if(fd < 0) printf( %d\n, errno); The code above will print 2 in the man pages, we can see that 2 is ENOENT No such file or directory In shell lab, your signal handlers must preserve errno 9

IO functions Needed for tshlab int open(const char *pathname, int flags); Some important flags: O_CREAT creates file if needed, opens for read/write O_RDWR opens for read/write O_RDONLY opens for read only int close(int fd); int dup2(int oldfd, int newfd); Needed for life ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count); off_t lseek(int fd, off_t offset, int whence); 10

IO and Fork() File descriptor management can be tricky. How many file descriptors are open in the parent process at the indicated point? How many does each child have open at the call to execve? int main(int argc, char** argv) { int i; for (i = 0; i < 4; i++) { int fd = open( foo, O_RDONLY); pid_t pid = fork(); if (pid == 0) { int ofd = open( bar, O_RDONLY); execve(...); } } // How many file descriptors are open in the parent? 11

Redirecting IO File descriptors can be directed to identify different open files. int main(int argc, char** argv) { int i; for (i = 0; i < 4; i++) { int fd = open( foo, O_RDONLY); pid_t pid = fork(); if (pid == 0) { int ofd = open( bar, O_WRONLY); dup2(fd, STDIN_FILENO); dup2(ofd, STDOUT_FILENO); execve(...); } } // How many file descriptors are open in the parent? 12

Redirecting IO At the two points (A and B) in main, how many file descriptors are open? int main(int argc, char** argv) { int i, fd; fd = open( foo, O_WRONLY); dup2(fd, STDOUT_FILENO); // Point A close(fd); // Point B... 13

Memory Access The processor tries to write to a memory address. List different steps that are required to complete this operation. 14

Memory Access The processor tries to write to a memory address. List different steps that are required to complete this operation. (non exhaustive list) Virtual to physical address conversion (TLB lookup) TLB miss Page fault, page loaded from disk TLB updated, check permissions L1 Cache miss (and L2 and) Request sent to memory Memory sends data to processor Cache updated 15

Address Translation with TLB Translate 0x15213, given the contents of the TLB and the first 32 entries of the page table below. 1MB Virtual Memory 256KB Physical Memory 4KB page size 2-way set associative Index Tag PP N Valid 0 05 13 1 3F 15 1 1 10 0F 1 0F 1E 0 2 1F 01 1 11 1F 0 3 03 2B 1 1D 23 0 VPN PPN Valid VPN PPN Valid 00 17 1 10 26 0 01 28 1 11 17 0 02 14 1 12 0E 1 03 0B 0 13 10 1 04 26 0 14 13 1 05 13 0 15 18 1 06 0F 1 16 31 1 07 10 1 17 12 0 08 1C 0 18 23 1 09 25 1 19 04 0 0A 31 0 1A 0C 1 0B 16 1 1B 2B 0 0C 01 0 1C 1E 0 0D 15 0 1D 3E 1 0E 0C 0 1E 27 1 0F 2B 1 1F 15 1 16

If you get stuck on TshLab Read the writeup! Do manual unit testing before runtrace and sdriver! Post private questions on piazza! Read the man pages on the syscalls. Especially the error conditions What errors should terminate the shell? What errors should be reported? 17