OS Labs 2/25/08 Frans Kaashoek MIT

Slides:



Advertisements
Similar presentations
Operating System.
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
1 Introduction to UNIX 2 Ke Liu
UC Santa Barbara Project 1 Discussion Bryce Boe 2011/04/12.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
1 Last Time: OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 UNIX 1 History of UNIX 2 Overview of UNIX 3 Processes in UNIX 4 Memory management in UNIX 5 The UNIX file system 6 Input/output in UNIX.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
Operating Systems Review. User Computer, including HW and SW.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Introduction Operating Systems’ Concepts and Structure Lecture 1 ~ Spring, 2008 ~ Spring, 2008TUCN. Operating Systems. Lecture 1.
Copyright Arshi Khan1 System Programming Instructor Arshi Khan.
Today’s topic Inter-process communication with pipes.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
Computer Organization Review and OS Introduction CS550 Operating Systems.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Linux in More Detail Shirley Moore CPS5401 August 29,
Unix Pipes Pipe sets up communication channel between two (related) processes. 37 Two processes connected by a pipe.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
Chapter 1 Introduction 1.1 What is an operating system
OPERATING SYSTEMS Goals of the course Definitions of operating systems Operating system goals What is not an operating system Computer architecture O/S.
Cli/Serv.: procs/51 Client/Server Distributed Systems v Objectives –look at how to program UNIX processes , Semester 1, Processes.
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
Background: Operating Systems Brad Karp UCL Computer Science CS GZ03 / M th November, 2008.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 8: Opening Files and Starting Processes.
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
LINUX System : Lecture 7 Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
Distributed System Concepts and Architectures 2.3 Services Fall 2011 Student: Fan Bai
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
1 Lecture 6 Introduction to Process Management COP 3353 Introduction to UNIX.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Recitation: Signaling S04, Recitation, Section A Debug Multiple Processes using GDB Debug Multiple Processes using GDB Dup2 Dup2 Signaling Signaling.
Chapter 1 Introduction  What is an operating system  History of operating systems  The operating system zoo  Computer hardware review  Operating system.
CSCI 330 UNIX and Network Programming
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
I/O Software CS 537 – Introduction to Operating Systems.
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
WHY AN OPERATING SYSTEM (OS) OS interacts with hardware and manages programs. Programs not expected to know which hardware they will run on. Must be possible.
4.1 Operating Systems Lecture 9 Fork and Exec Read Ch
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Chapter 3 The Programming Interface Chien-Chung Shen CIS/UD
LINUX An Introduction Wan Ahmad Tajuddin Wan Abdullah Universiti Malaya KL ACGRID-II 2009.
10/2/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
Introduction to Operating Systems Concepts
Process API COMP 755.
Mid Term review CSC345.
2/25/08 Frans Kaashoek MIT OS abstractions 2/25/08 Frans Kaashoek MIT
Programming Assignment # 2 – Supplementary Discussion
IPC Prof. Ikjun Yeom TA – Hoyoun
Tutorial: The Programming Interface
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Outline Operating System Organization Operating System Examples
Lecture 6 Introduction to Process Management
System Programming: Process Management
Presentation transcript:

OS Labs 2/25/08 Frans Kaashoek MIT

New labs for Tsinghua OS course Operating systems can be misleadingly simple –Clean simple abstractions, easily understandable in isolation –Complexity is in how their implementations interact Learn by doing, focus on interactions –How do hardware interrupts interact with kernel and user-level processes? –How to use virtual memory to solve many problems? Labs build a “complete” OS from the ground up

Why might you care? Perhaps you will build an OS Perhaps you will design hardware Or write a device driver, network stack, or a file system Or need to diagnose application bugs or performance Or you just want to know how computers work Or you just want to have fun programming

Lab OS: JOS JOS has an exokernel/hypervisor structure –Different than Linux’s organization –Forces you to see something else and think Small kernel with low-level API LibOS w. Unix API sh LibOS w. Unix API ls fork exofork Labs based on MIT’s OS class (6.828)

The labs: bottom up 1.Booting 2.Memory management 3.User-level environments 4.Preemptive multitasking 5.File system and spawn 6.A shell required optional

Development environment Tools: gcc, make, etc. Target hardware platform: x86 PC –For debugging: bochs and qemu Lab assigments come with tests Details at course web pages

sh: shell Interactive command interpreter Interface (“the shell”) to the operating system Examples of shell commands: –$ ls # create process –$ ls > tmp1 # write output to file –$ sh tmp1 # run sh script –$ sort tmp | uniq | wc # process communicate with pipe –$ compute-pi & # run program in background –$ …. OS ideas: isolation, concurrency, communication, synchronization

shell implementation while (1) { printf(“$”); readcommand(command, args); pid = fork(); // new process; concurrency if (pid == 0) { // child? exec (command, args, 0); // run command } else if (pid > 0) { // parent? r = wait (0);// wait until child is done } else { perror(“Failed to fork\n”); }

Input/Output (I/O) I/O through file descriptors –File descriptor may be for a file, terminal, … Example calls; –read(fd, buf, sizeof(buf)); –write(fd, buf, sizeof(buf)); Convention: –0: input –1: output –2: error Child inherits open file descriptors from parents

I/O redirection Example: “ls > tmp1” Modify sh to insert before exec: close(1); // release fd 1 fd = create(“tmp1”, 0666); // fd will be 1 No modifications to “ls”! “ls” could be writing to file, terminal, etc., but programmer of “ls” doesn’t need to know

Pipe: one-way communication int fdarray[2]; char buf[512]; int n; pipe(fdarray);// returns 2 fd’s write(fdarray[1], “hello”, 5); read(fdarray[0], buf, sizeof(buf)); buf contains ‘h’, ‘e’, ‘l’, ‘l’, ‘o’

Pipe between parent & child int fdarray[2]; char buf[512]; int n, pid; pipe(fdarray); pid = fork(); if(pid > 0) { write(fdarray[1], "hello", 5); } else { n = read(fdarray[0], buf, sizeof(buf)); } Synchronization between parent and child –read blocks until there is data How does the shell implement “a | b”?

Implementing shell pipelines int fdarray[2]; if (pipe(fdarray) < 0) panic ("error"); if ((pid = fork ()) == 0) { // child (left end of pipe) close (1); tmp = dup (fdarray[1]); // fdarray[1] is the write end, tmp will be 1 close (fdarray[0]); // close read end close (fdarray[1]); // close fdarray[1] exec (command1, args1, 0); } else if (pid > 0) { // parent (right end of pipe) close (0); tmp = dup (fdarray[0]); // fdarray[0] is the read end, tmp will be 0 close (fdarray[0]); close (fdarray[1]); // close write end exec (command2, args2, 0); } else { printf ("Unable to fork\n"); }

OS abstractions and ideas Processes (fork & exec & wait) Files (open, create, read, write, close) File descriptor (dup,..) Communication (pipe) Also a number of OS ideas: –Isolation between processes –Concurrency –Coordination/Synchronization Your job: implement abstractions and understand ideas

What will you know at the end? Understand OS abstractions in detail Intel x86 The PC platform The C programming language Unix abstractions Experience with building system software –Handle complexity, concurrency, etc.

Lab lectures Monday 3/3: –Intel x86: introduction, assembly, stack –Helps with lab 1 Monday 3/17: –Intel x86 memory management & interrupts –Helps with lab 2 & 3

Bonus lectures: special topics 1.OS architecture 2.Virtual machines 3.File systems 4.Security 5.Multicore 6.Finding errors in OSes Some Wednesdays; see schedule

Have fun!