A2 Design Considerations. CS161, Spring

Similar documents
CS61 Scribe Notes Date: Topic: Fork, Advanced Virtual Memory. Scribes: Mitchel Cole Emily Lawton Jefferson Lee Wentao Xu

CS471 ASST2. System Calls

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan

Process Management 1

Process Management! Goals of this Lecture!

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

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

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

Section 2: Processes

Unix Processes. What is a Process?

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

(In columns, of course.)

Operating System Labs. Yuanbin Wu

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

CS350 Operating Systems Fall Assignment Two

CS 322 Operating Systems Practice Midterm Questions

Operating Systems and Networks Assignment 2

Processes. What s s a process? process? A dynamically executing instance of a program. David Morgan

Mon Sep 17, 2007 Lecture 3: Process Management

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

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

CS 3733 Operating Systems

SOFTWARE ARCHITECTURE 3. SHELL

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

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

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

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

Operating System Structure

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

University of Ottawa School of Information Technology and Engineering

TDDB68 Lesson 2 Pintos Assignments 3 & 4. Mattias Eriksson 2010 (or

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

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

W4118: OS Overview. Junfeng Yang

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

Killing Zombies, Working, Sleeping, and Spawning Children

Process Management! Goals of this Lecture!

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

CS 31: Intro to Systems Processes. Kevin Webb Swarthmore College March 31, 2016

Processes and Threads

Project 2--User Programs

csci3411: Operating Systems

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Project 2: Shell with History1

Operating Systems. II. Processes

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

Design Overview of the FreeBSD Kernel CIS 657

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

Operating Systems and Networks Assignment 9

CS 201. Processes. Gerson Robboy Portland State University

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

Problem Set: Processes

Lecture 2 Process Management

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Chap 4, 5: Process. Dongkun Shin, SKKU

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions

Computer Systems Assignment 2: Fork and Threads Package

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

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

CPS 310 first midterm exam, 10/6/2014

CS510 Operating System Foundations. Jonathan Walpole

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Fall 2015 COMP Operating Systems. Lab #3

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

SE350: Operating Systems

Midterm Exam CPS 210: Operating Systems Spring 2013

Project 2: User Programs

Exam Guide COMPSCI 386

Processes. Process Concept

Operating Systems. Process scheduling. Thomas Ropars.

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

CSE 153 Design of Operating Systems Fall 2018

(MCQZ-CS604 Operating Systems)

Problem Set: Processes

Processes COMPSCI 386

NAME SYNOPSIS DESCRIPTION. Behavior of other Perl features in forked pseudo-processes. Perl version documentation - perlfork

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

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

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

Processes. CS439: Principles of Computer Systems January 24, 2018

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

Processes. CS3026 Operating Systems Lecture 05

Processes. Processes (cont d)

Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

Virtual File System. Don Porter CSE 306

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

2/14/2012. Using a layered approach, the operating system is divided into N levels or layers. Also view as a stack of services

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

OPERATING SYSTEMS: Lesson 4: Process Scheduling

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Chapter 4: Processes. Process Concept

Inter-Process Communication

Assignment 1. Teaching Assistant: Michalis Pachilakis (

Transcription:

A2 Design Considerations CS161, Spring 2014 http://goo.gl/izxych

Agenda 1. processes 2. file descriptors 3. fork 4. waitpid & exit 5. exec 6. scheduler 7. suggestions for testing 8. lessons learned from Kenny

Design Document These notes contain lots of open-ended questions to get you think about your design. Be sure to address these questions in your design document.

Processes a process is an address space & threads our recommendation: only implement singlethreaded processes feel free to implement multi-threaded processes...

Processes What per-process state might you want? What per-thread state might you want? How is the **first** process created? When?

Processes What per-process state might you want? pid, address space, fd table, cwd,... What per-thread state might you want? execution state, user stack pointer, How is the **first** process created? When?

Processes - Thread States What are the possible thread states? TIP: Draw a state transition diagram on how a thread can go from one state to the next.

pid process ids can pids be recycled? how do you allocate & free them? how do you prevent multiple processes from having the same pid? is there a limit to pids? for waitpid(pid): given the pid, how do you get to the process with that pid?

bootstrapping where in code should things be bootstrapped? grep for bootstrap what kinds of things might need bootstrapping? e.g. pid allocation data structures depends on your implementation

file descriptors open(), close(), read(), write(), lseek(), dup2(), chdir(), getcwd() see man pages in the man/ directory for a full specification of these system calls a **file descriptor** represents an index into a table of file descriptors (file descriptor table) All processes have the standard fds open by default: stdin (0), stdout (1), stderr(2) How do you initialize these file descriptors? What kernel objects do these correspond to?

a note about VFS virtual file system abstraction between OS and file-like systems API that file systems implement allow you to treat all file systems in the same way by working with vnodes, vfs_*, VOP_* operations VOP_*, vfs_* operations will delegate to the actual implementation for that file system (think object-oriented programming) example: vfs_open() -> sfs_open() for sfs objects you will be working at the level of vnodes for ASST2

file descriptors - file descriptor table Who owns the fd table abstraction? What happens to a fd table when a process forks or exits? What happens to the fd table and seek position when: you open() on the same file twice, and seek on one of them? you seek on a file descriptor returned by dup2()? you call fork, and the child seeks on a file descriptor?

file descriptors - file descriptor table How should you assign new file descriptors? Should there be a limit on file descriptors? Each file descriptor has an associated file offset. What happens if you open the same file twice? How should you convert file descriptors to more meaningful information? How are open files represented in the kernel? vnode, part of the VFS (virtual file system layer)

file descriptors - file descriptor table

file descriptors - details lseek() what if you seek beyond end of file? is that legal? VOP_TRYSEEK how do you handle 64-bit offset values? read()/write() look at struct uio close() a kernel object might be referenced by multiple fds what happens if we close() a file descriptor returned by dup2()? when should the underlying kernel object actually be freed TIP: use reference counting

exit() & waitpid() What process state can be cleaned up on exit()? on waitpid()? When does a process and thread *actually* get destroyed? A thread/process can t destroy itself...

exit() & waitpid() Who can wait for our exit status? the parent How does the parent collect the exit status? waitpid() should fail it the pid doesn t exist, or if the pid is not a child of the current process. how do you enforce this? how do you maintain the process hierarchy?

exit() & waitpid() - synchronization How does the parent wait for the child to finish? How does the child notify the parent that it has exited? What are the scenarios to consider?

exit() & waitpid() - synchronization How does the parent wait for the child to finish? How does the child notify the parent that it has exited? What are the scenarios to consider? parent exits, then child exits who will clean up the children? parent waits, then child exits child exits, then parent waits child exits, then parent exits without waiting who will clean up the children?

fork() create a new process and thread what needs to be copied? what needs to be different?

fork() create a new process and thread what needs to be copied? process stuff: address space, file descriptors, cwd thread stuff: execution state, stack pointer, what needs to be different? pid, return values how do you change the return value in child/parent? trapframe!

fork() - synchronization How do you setup the process hierarchy? How does the child return to user land? How does the parent wait for the child to finish initializing? why? parent process needs to return the child pid in fork() How does the child wait for the parent to finish initializing? why? setting up process hierarchy

fork() - error handling need to allocate lots of things for the child: process struct, pid, address space, file descriptors, new thread, etc. what if an error occurs? need to cleanup/free all the resources that we allocated, and return error to userland what if an error occurs in child after thread_fork()? how does the parent cleanup now?

execv replace a process s address space and execution state with new binary kind of like runprogram() does NOT return on success need to be careful on how to handle and setup arguments execv is the one that sets up argc and argv for main()

execv What does execv do?

execv What does execv do? open binary file create new address space load executable there copy arguments from old address space into new address space define the stack enter usermode

execv - arguments How do you copy in arguments from old address space? copyin() - why do we need this? user level pointers are dangerous! How do you copy out arguments to new address space? copyout() How should the arguments be laid out in the new address space? this is the hard part. Where should the stack pointer be after arguments have been copied into the new address space?

execv - arguments Old address space: char *prog = ls ; // argv must be // NULL-terminated char *argv[3]; argv[0] = ls ; argv[1] = foo ; argv[2] = NULL; execv(prog, argv); What does the new address space look like?

execv - arguments Old address space: char *prog = ls ; // argv must be // NULL-terminated char *argv[3]; argv[0] = ls ; argv[1] = foo ; argv[2] = NULL; execv(prog, argv); new address space:

execv - arguments Where is the new stack pointer? Why do argv[0] and argv[1] each occupy 4 bytes? new address space: Why is the box at 800 empty? Why is there nothing at 795? Why are 788-791 all 0?

execv - arguments Where is the new stack pointer? at the base of argv Why do argv[0] and argv[1] each occupy 4 bytes? because they are pointers, and sizeof(pointer) == 4 Why is the box at 800 empty? 0x80000000 is the start of kernel memory Why is there nothing at 795? pointers must be 4-byte aligned Why are 788-791 all 0? argv must be NULL terminated in the new address space new address space:

execv - synchronization can multiple processes call execv at the same time?

execv - synchronization can multiple processes call execv at the same time? is this feasible? what will determine if this is possible? memory constraints? other resource constraints?

execv - error handling What if you free your old address space, and then an error occurs when copying over to new address space?

scheduler do something better than round-robin convince us why it s good make it easily swappable and tunable use #ifdef s what parameters can be used to tune your scheduler? what bookkeeping information do you need? how do you collect these statistics? when/how should you migrate a thread between processors?

scheduler - key metrics cpu utilization: % time CPU is running threads cpu throughput: # jobs per time turnaround time: {end time} - {start time} response time: total time jobs spend on ready queue waiting time: total time jobs spend on wait/sleep queue

scheduler - goals efficiency - maximize cpu utilization & throughput latency - minimize response time fairness - distribute resources equitably

scheduler - strategies Random (it s actually pretty good) MLFQ (multilevel feedback queue) Lottery First-come, first serve Shortest remaining time first others

suggestions for testing kernel level tests (from the kernel menu) feel free to add more kernel-level tests/commands to test kernel data structures/invariants (e.g. pid allocation) userland tests get runprogram() to work ( p in kernel menu) first can test userland programs without implementing fork, waitpid, exec after fork, waitpid, exec are implemented, you can now test more thoroughly using the userland shell ( s in kernel menu) no gdb at user level :( feel free to add more simple userland programs to test system calls e.g. opening a file, reading, writing, fork, wait, exec

lessons learned from Kenny synchronization and error handling are the hardest part THINK VERY CAREFULLY about synchronization before starting to code coding without a synchronization plan eventually require massive rewrite use goto pattern for error handling/resource cleanup little memory (4MB) failures are the norm expect lots of bugs to occur from improper error handling and resource cleanup check your invariants with KASSERT fail quickly faster debugging sessions review your partner s commits! you and your partner should agree on a coding style and be consistent use git show COMMIT or git diff COMMIT1 COMMIT2 reviewing your partner s commits less likely to be caught off guard by changes you didn t know about drink some coffee coding when you re sleepy more errors/harder to debug/need rewrite