TDDB68 Lesson 3. Simon Ståhlberg
|
|
- Naomi Hunter
- 6 years ago
- Views:
Transcription
1 TDDB68 Lesson 3 Simon Ståhlberg
2 Contents Overview of lab 3 A: Exec, wait, exit B: Program arguments C: Termination of ill-behaving user processes Testing your implementation Overview of lab 4 File system The readers-writers problem Additional system calls Testing your implementation
3 Lab 3: Overview Part A: Execution of several user processes Implement Exec, Wait and Exit Exec: starts up a child process that executes the given file Exit: terminates the process, frees allocated resources and saves the exit status somewhere Wait: waits on a child process to terminate and return its exit code Regardless of the order of wait and exit, wait must return the child s exit status. We take a closer look at some scenarios that you have to think about Alive counting to decide who should free dynamically allocated memory Part B: Handling program arguments Currently, Pintos does not support arguments to programs Remember *esp = PHYSBASE - 12? We needed - 12 (bytes) to compensate for the missing arguments. Remove it and add proper support What is on the initial stack Part C: Termination of ill-behaving user processes How to be paranoid about user arguments Stack pointer, pointers in general, strings, and buffers
4 Lab 3: Part A - Exec pid_t exec (const char *cmd_line) The first word of the string cmd_line is a file name, the rest are the arguments to the program. Spawn a new child process that loads the file and executes it. If the child process could load and start executing the file then return the process ID (PID) of the child, return -1 otherwise The current implementation of exec does not wait to see if the child could load the file/program Make exec wait for the new process to finish loading before returning the PID Hint: The current implementation is process_execute Hint: You can assume that TID and PID are the same thing in Pintos Hint: A process can have several children at the same time
5 Lab 3: Part A - Exec start_process load (the loaded program) (some code) Child process_execute thread_create Wake up the parent and notify the parent whether it can start executing Parent Wait for the child to start executing
6 Lab 3: Part A - Exec The following functions and lines of code are of interest. tid_t process_execute (const char *file_name) tid = thread_create (file_name, PRI_DEFAULT, start_process, fn_copy); // Inside process_execute tid_t thread_create (const char *name, int priority, thread_func *function, void *aux) static void start_process (void *fname) start_process is the function that the new thread starts executing, and aux is the argument to said function
7 Lab 3: Part A - Exec Hint: The only place where start_process is "called" is in process_execute. Hence, you can extend the parameter of start_process (fname) and the argument to thread_create (fn_copy) to whatever you want (e.g. a pointer to a struct) Hint: The initial thread main does not have any parent, and is not created by thread_create, but it is initialised by init_thread
8 Lab 3: Part A - Exit void exit (int status) The exit status has to be made available to its parent process. More on this shortly The process has to release all its allocated resources, such as free dynamically allocated memory, close opened files, close network connections, and so on. Release whatever resource you allocate in your solution If the process crashes for any reason, then the exit status should be -1. Furthermore, all of the allocated resources must be released Hint: Release resources in thread_exit() or process_exit() Hint: At exit, do: (make check will fail otherwise) printf("%s: exit(%d)\n", thread-name, thread-exit-value)
9 Lab 3: Part A - Wait int wait (pid_t pid) The calling process waits for the child process with the PID to terminate and receives its exit status. If the child has already terminated, its exit status should be returned immediately In the last case, the exit status must be saved somewhere since the process does not exists Scenarios: Parent calls wait before the child terminates Parent calls wait after the child terminates Parent terminates before the child without calling wait Parent terminates after the child without calling wait In each of these scenarios, your code must work and shared resources must be released by whoever terminates last Remember that a process can have several children!
10 Lab 3: Part A - Wait The exit status is only available until the first wait call by the parent. If the parent waits twice on the same child, then the second wait returns -1 Hint: Since the exit status has to be available even after the child terminates, then the exit status can be stored in dynamically allocated memory Hint: A common approach is to have a struct of data for every parent-child pair. The struct contains, amongst other things, the exit status As we noted earlier, this struct must be freed by whoever terminates last, i.e. either the parent or the child
11 Lab 3: Part A - Wait Scenario: parent waits for child to exit Important! Busy waiting is NOT allowed! Child exit(x) Free the exit value! Parent exec wait(child) Waits returns X
12 Lab 3: Part A - Wait Scenario: child exits before the parent, and then the parent calls wait Child exit(x) store X on the heap Free the exit value! Parent exec wait(child) returns X
13 Lab 3: Part A - Wait Scenario: parent never waits for the child and exits before it Child exit(x) Parent exec exit(y) Free the exit value!
14 Lab 3: Part A - Wait How to detect who is the last to exit? Hint: Keep a counter, together with the exit status, with the initial value 2. When the parent and child exit, decrement it by 1. The value 0 represents that both the parent and the child has exited, and whoever decrements it to 0 should free the memory Hint: Protect the counter with synchronisation! Pintos might leak memory otherwise! Child struct parent_child { int exit_status; pcs int alive_count; /*... whatever else you need... */ }; Parent
15 Lab 3: Part B Pintos does not currently support program arguments. For example: insult -s 17 Remember *esp = PHYSBASE - 12? The arguments require at least 12 bytes on the stack. Remove the subtraction! We will go through how to setup the stack in order to support program arguments
16 Lab 3: Part B To run a program with arguments in Pintos: Pintos (note the single quotes): pintos --qemu --run 'insult -s 17' System call: exec("insult -s 17");
17 Lab 3: Part B Suppose we do this: insult -s 17 The parameters of the main function of C programs are int argc and char **argv. In this example: argc is 3 argv[0] is "insult\0" argv[1] is "-s\0" argv[2] is "17\0" argv[argc] is NULL Note that the length of the array is actually 4, but the last element is always NULL (required by the C standard)
18 Lab 3: Part B Every time you do a function call, a stack frame is pushed on the stack: Stack frame The function main is never really called, but the layout is the same The parameters and the return address of the stack frame is pushed onto the stack by Pintos (your code!) { We touched on this in the first lesson Parameters Return address Local variables Growth direction
19 Lab 3: Part B The string is stored on the stack Parameters Local variables { { { { Address Name Data Type 0xbffffffd argv[2][...] "17\0" char[3] 0xbffffffa argv[1][...] "-s\0" char[3] 0xbffffff3 argv[0][...] "insult\0" char[7]... word-align unused 0xbffffff0 word-align unused 0xbfffffec argv[3] NULL char * 0xbfffffe8 argv[2] 0xbffffffd char * 0xbfffffe4 argv[1] 0xbffffffa char * 0xbfffffe0 argv[0] 0xbffffff3 char *... 0xbfffffc8 argv 0xbfffffe0 char ** 0xbfffffc4 argc 3 int 0xbfffffc0 return address unused void (*) () Stack grows towards 0 Adding all of this to the stack is what Lab 3: Part B is about! Adjust the stack pointer so it is divisible by 4 } } The function never returns
20 Lab 3: Part B Step 1: Change *esp = PHYSBASE - 12; to *esp = PHYSBASE; (the size of the argc (int), argv (char**) and argv[0] is 12) Step 2: Put the words on the stack, word alignment, the argv array, argc and the return address Hint: start_process calls load, which calls setup_stack. Hint: Take a look at setup_stack(void **esp). Note that the argument is a pointer to the stack pointer! In other words, you must dereference twice to write to the stack, and dereference once to change the stack pointer itself! Hint: setup_stack is called by load, and after the call there is debug code for printing the stack. To print the stack, uncomment /*#define STACK_DEBUG*/
21 Lab 3: Part B Hint: You get a string, such as "insult -s 17\0", and you need to split it up in smaller parts. Use (in lib/string.[c h]): char * strtok_r(char *s, const char *delimiters, char **save_ptr) The following loop tokenises the string s = "insult -s 17\0". for (token = strtok_r (s, " ", &save_ptr); token!= NULL; token = strtok_r (NULL, " ", &save_ptr)) {... } Every iteration you get the next word, i.e. "insult\0", "-s\0" and "17\0". However, it does so destructively! This is what the memory looks after the loop: s = "insult\0-s\017\0" You need to save a pointer to every word Hint: Read Pintos documentation 3.5.1, it presents another stack print!
22 Lab 3: Part C Argument paranoia: nothing the user processes does should be able to crash Pintos All user processes i Pintos, even when running in unsupervised mode, use virtual memory (a page table). Dereferencing a pointer not in the page table leads to errors such as invalid page fault or segmentation fault For example: create((char*) 1, 1); is an invalid call since address 1 is in kernel space. Furthermore, it is not a string! Another example: read(stdin_fileno, 0xc , 666); writes data to kernel space (will likely overwrite something important) Hence, ALL pointers from the user processes to the kernel must be checked! Including the stack pointer, strings, and buffers
23 Lab 3: Part C How to validate a pointer: A valid pointer from a user process is: below PHYS_SPACE in virtual memory (not kernel memory) associated with a page in the page table for the process (use pagedir_get_page) If some pointer is not valid, then terminate the process! The exit status is then -1 If you were to dereference an invalid pointer that is below PHYS_SPACE, then you get an error. It is possible to take care of the problem when the error occurs, but it is more challenging (although, it is faster: read the documentation if you want to attempt this) Hint: Read Pintos documentation 3.1.5
24 Lab 3: Part C Suppose a process calls create((char *) PHYS_BASE , 17); The function filesys_create does not check the string, and the string is not NULL. The call will likely crash Pintos! Hint: You must check that the char * is a string by iterating over every character of it, and check that the pointer to it is a valid pointer Hint: In other words, for strings, you must check every character until you find a '\0'. Remember to first check the pointer, then read it! (You might get an error otherwise)
25 Lab 3: Part C Suppose a process calls write(1, malloc(1), ); Obviously, the arguments are invalid since the size of the buffer is 1, but the process claims it is much bigger! If we were to read from the buffer, then we would get an error. It is not sufficient to only test the pointer, we must also check its size! Hint: We must check that every possible pointer to the buffer is valid. In other words, we must test pointers (at most, if you want to optimise it then you can compute where the page boundaries are, and check those) Hint: In contrast to strings, the size of the buffer is given and we do NOT have to search for a '\0'
26 Lab 3: Part C The user process can modify its own stack pointer: asm volatile ( movl $0x0, %esp; int $0x30 ::: ); So you have to check the stack pointer if you want to read what it points to. If you increment the stack pointer, then you have to redo the check! In other words, you have to check the stack pointer before reading the system call number, before reading the first argument, and so on
27 Lab 3: Testing Sadly, you cannot test until you have finished both part A and part B When you have finished part A and B, then you can test your implementation with: make check The following tests are for Lab 1: halt, exit, create-normal, create-empty, create-null, create-long, create-exists, createbound, open-normal, open-missing, open-boundary, open-empty, open-twice, close-normal, close-stdin, close-stdout, close-badfd, read-boundary, read-zero, read-stdout, read-bad-fd, writenormal, write-boundary, write-zero, write-stdin, write-bad-fd Most of the exec-* and wait-* tests (and Lab 1) should pass when you have finished Part A and B Hint: You can run a single test (from userprog/build) with: make tests/userprog/halt.result The rests are for when Part C is finished (~60 tests in total)
28 Lab 4: Overview Synchronising the file system in Pintos The readers-writers problem Additional system calls (seek, tell, filesize, remove Testing your implementation Lab 3 is time consuming, but Lab 4 should take about as much time as Lab 1
29 Lab 4: File system devices/disk.[h c] - Low-level operations on the drive (shared and already synchronised) filesys/free-map.[h c] - Operations on the map of free disk sectors (shared) filesys/inode.[h c] - Operations on inodes, which represents an individual file. When you write/read data to/from an inode then you modify the actual physical file (shared) filesys/filesys.[h c] - Operations on the file system, such as create, open, close, remove, and so on (shared) filesys/directory.[h c] - Operations on directories (partially shared) filesys/file.[h c] - A file object that contains an inode and things like a seek position. Every process has its own object (not shared)
30 Lab 4: File system Your assignment is to synchronise the files that contains data which is shared between multiple processes and are not already synchronised Use locks and semaphores!
31 Lab 4: Readers-writers It is easy to synchronise the file system by only using one lock everywhere, but that leads to extremely poor performance We have these requirements: Several readers are able to read from the same file at the same time Only one writer is able to a specific file at the same time Several writer are able to write to different files at the same time When a process is reading from a file, then no process can write to the file at the same time When a process is writing to a file, then no process can read from the file at the same time Hint: There is at most 1 inode per physical file
32 Lab 4: Readers-writers The readers-writers problem is how to achieve the aforementioned requirements. There are several solutions with different properties Hint: Wikipedia has a few algorithms writers_problem Hint: The solution with readers-preference is easy to implement, but might starve writers
33 Lab 4: System calls In addition to synchronising the file system, you also have to implement these system calls: void seek (int fd, unsigned position): Sets the current seek position of the file unsigned tell (int fd): Gets the seek position of the file int filesize (int fd): Returns the file size of the file bool remove (const char *file_name): Removes the file. Hint: The removal of the file is delayed until it is not opened by any process (make sure that this counter is synchronised) Hint: Use built-in functions Hint: Check for invalid arguments!
34 Lab 4: Hints Some questions that you should ask yourself: What can happen, in the worst case, if two processes try to... Create and remove the same file at the same time? Create and remove the same directory at the same time? Open the same file at the same time? Open and close the same file at the same time? And so on! Many of these operations should, from each other perspective, be atomic" This is NOT a complete list!
35 Lab 4: Testing To test your implementation, we provide the following user programs: pfs.c pfs_reader.c pfs_writer.c The program pfs read and write to the same file concurrently: 2 writers that repeatedly fill the file with an arbitrary letter 3 readers that repeatedly read the file and checks that all the letters are the same If the letters differ for the readers, then the test fails Run pfs many times and check the result each time! Inconsistency due to lack of synchronisation may not happen every time Hint: The Linux Mint computers might be too fast, change #define TIME_SLICE 4 (threads/thread.c) to a lower value, or #define TIMER_FREQ 100 (devices/ timer.h) to a higher value, to make the scheduler to switch between processes more often
36 Questions? Remember! If you pass the labs by March 10, 2017 in webreg then you get bonus points!
TDDB68 Lesson 2 Pintos Assignments 3 & 4. Mattias Eriksson 2010 (or
TDDB68 Lesson 2 Pintos Assignments 3 & 4 Mattias Eriksson 2010 mater@ida.liu.se (or mattias.eriksson@liu.se) some slides by Viacheslav Izosimov 2007-2008 Instead of Motivation Plan for something like this:
More informationTDDB Lesson 3 Pintos Assignments (2), 3 & 4. Erik Hansson
TDDB68 2015 Lesson 3 Pintos Assignments (2), 3 & 4 Erik Hansson erik.hansson@liu.se Most slides by Mattias Eriksson 2009-2010 and Viacheslav Izosimov 2007-2008 Remember Pass assignments on time to get
More informationTDDB Lesson 2 Pintos Assignments (2), 3 & 4. Erik Hansson
TDDB68 2013 Lesson 2 Pintos Assignments (2), 3 & 4 Erik Hansson erik.hansson@liu.se Most slides by Mattias Eriksson 2009-2010 and Viacheslav Izosimov 2007-2008 Instead of Motivation Some of you should
More informationTDDB Lesson 3 Pintos Assignments (2), 3 & 4. Erik Hansson
TDDB68 2016 Lesson 3 Pintos Assignments (2), 3 & 4 Erik Hansson erik.hansson@liu.se Most slides by Mattias Eriksson 2009-2010 and Viacheslav Izosimov 2007-2008 Plan your time Plan your time with your
More informationLaboratory work in TDDI04 Pintos Assignments 2, 3
Laboratory work in TDDI04 Pintos Assignments 2, 3 Viacheslav Izosimov 2008-01-28 viaiz@ida.liu.se Instead of Motivation The deadline for Lab 1 is extended to 1st of February! KERNEL PANIC!!! YOUR PINTOS
More informationLaboratory work in TDDB68 Pintos Assignments 2, 3. Viacheslav Izosimov
Laboratory work in TDDB68 Pintos Assignments 2, 3 Viacheslav Izosimov 2007-09-18 viaiz@ida.liu.se Timeline Lab 2: System calls Description Pintos stack Pintos memory Pintos file system Halt, Exit Create,
More informationTDDB68. Lesson 1. Simon Ståhlberg
TDDB68 Lesson 1 Simon Ståhlberg Contents General information about the labs Overview of the labs Memory layout of C programs ("Lab 00") General information about Pintos System calls Lab 1 Debugging Administration
More informationAccording to this plan, you should have started with Lab 2 now Around 50% have passed Lab 1. The environment (1)
TDDB68 Lesson 2 Pintos Assignments 2 & 3 Mattias Eriksson 2009 mater@ida.liu.se some slides by Viacheslav Izosimov 2007-2008 Comments on muddy card evaluation Environment to build, run and test on Windows/
More informationUser Programs. Computer Systems Laboratory Sungkyunkwan University
Project 2: User Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Supporting User Programs What should be done to run user programs? 1. Provide
More informationProject 2-1 User Programs
Project 2-1 User Programs Prof. Jin-Soo Kim ( jinsookim@skku.edu) T.A. Sejun Kwon (sejun000@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Supporting User Programs
More informationProject 2: User Programs
Project 2: User Programs Presented by Jaishankar Sundararaman 21 February 2008 Till now All code part of Pintos Kernel Code compiled directly with the kernel This required that the tests call some functions
More informationProject 2: User Programs
Project 2: User Programs CS140 - Winter 2010 Slides by Andrew He, adapted from previous CS140 offerings Overview Project 2 is due Thursday, February 4 This project requires an understanding of: How user
More informationPintos Project 2 User Programs. September 28, 2016
Pintos Project 2 User Programs September 28, 2016 Overview What are user programs? Anything you run on the command line: ~$ls ~$git push ~$./my_project arg1 arg2 Overview of Part 1: Setup Stack User Hey
More informationCS 140 Project 2: User Programs. Fall 2015
CS 140 Project 2: User Programs Fall 2015 Important Dates Project 1: DUE TODAY (Friday, October 9 th ) at 12pm Project 2 will be due Friday, October 23 rd at 12pm 2 weeks Start early J 2 Overview Project
More informationPintos Project 2 User Programs
1 Pintos Project 2 User Programs COS 450 - Fall 2018 Project 1 Submissions Easy Things to Fix 2 Project submission Code style ASSERT and malloc() Design document questions Code Style 1.2.2.2 3 Match the
More informationSection 7: Wait/Exit, Address Translation
William Liu October 15, 2014 Contents 1 Wait and Exit 2 1.1 Thinking about what you need to do.............................. 2 1.2 Code................................................ 2 2 Vocabulary 4
More informationProject 2--User Programs
Project 2--User Programs Jason Bau CS140 Winter 09 Slides Acknowledgements to previous CS140 TAs User Program/Process What happens in Unix shell when? myth13:~/> cp r pintos. 1. Shell handles user input
More informationProject-2 Review. (Extending the functionality of PintOS user program implementation) Summer 2018
Project-2 Review (Extending the functionality of PintOS user program implementation) Summer 2018 Overview Necessities and Organization Argument passing in PintOS Implementation of System Calls Metedata
More informationCS 322 Operating Systems Practice Midterm Questions
! CS 322 Operating Systems 1. Processes go through the following states in their lifetime. time slice ends Consider the following events and answer the questions that follow. Assume there are 5 processes,
More informationProject 5: File Systems
Project 5: File Systems by Ben Pfaff USF modifications by Greg Benson Chapter 1: Project 5: File Systems 1 1 Project 5: File Systems In the previous two assignments, you made extensive use of a file system
More informationby Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha
CS 111 Scribe Notes for 4/11/05 by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha Processes What is a process? A process is a running instance of a program. The Web browser you're using to
More informationCS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES
CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES Your name: SUNet ID: In accordance with both the letter and the spirit of the Stanford Honor Code, I did not cheat on this exam. Furthermore,
More informationTDDB Lesson 2 Introduction to Pintos Assignments (1) and 2
TDDB68 2015 Lesson 2 Introduction to Pintos Assignments (1) and 2 Erik Hansson erik.hansson@liu.se Most slides by Mattias Eriksson 2009-2010 and Viacheslav Izosimov 2007-2008. Outline Administration Introduction
More informationC Review. MaxMSP Developers Workshop Summer 2009 CNMAT
C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***
More informationCPS 310 first midterm exam, 10/6/2014
CPS 310 first midterm exam, 10/6/2014 Your name please: Part 1. More fun with fork and exec* What is the output generated by this program? Please assume that each executed print statement completes, e.g.,
More informationCS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018
CS 31: Intro to Systems Pointers and Memory Kevin Webb Swarthmore College October 2, 2018 Overview How to reference the location of a variable in memory Where variables are placed in memory How to make
More informationOS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2
OS COMPONENTS OVERVIEW OF UNIX FILE I/O CS124 Operating Systems Fall 2017-2018, Lecture 2 2 Operating System Components (1) Common components of operating systems: Users: Want to solve problems by using
More information518 Lecture Notes Week 3
518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to
More informationOperating System Structure
Operating System Structure CSCI 4061 Introduction to Operating Systems Applications Instructor: Abhishek Chandra Operating System Hardware 2 Questions Operating System Structure How does the OS manage
More informationSection 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2
CS162 September 15, 2016 Contents 1 Warmup 2 1.1 Hello World............................................ 2 2 Vocabulary 2 3 Problems 3 3.1 Join................................................ 3 3.2 Stack
More informationCS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016
CS 31: Intro to Systems Pointers and Memory Martin Gagne Swarthmore College February 16, 2016 So we declared a pointer How do we make it point to something? 1. Assign it the address of an existing variable
More informationMy malloc: mylloc and mhysa. Johan Montelius HT2016
1 Introduction My malloc: mylloc and mhysa Johan Montelius HT2016 So this is an experiment where we will implement our own malloc. We will not implement the world s fastest allocator, but it will work
More informationCMSC 412 Project #3 Threads & Synchronization Due March 17 th, 2017, at 5:00pm
CMSC 412 Project #3 Threads & Synchronization Due March 17 th, 2017, at 5:00pm Overview User level threads. You will implement user level threads where each thread has it s own stack, but shares the program,
More informationMidterm Exam #1 February 28, 2018 CS162 Operating Systems
University of California, Berkeley College of Engineering Computer Science Division EECS Spring 2018 Anthony D. Joseph and Jonathan Ragan-Kelley Midterm Exam #1 February 28, 2018 CS162 Operating Systems
More informationECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017
ECE 550D Fundamentals of Computer Systems and Engineering Fall 2017 The Operating System (OS) Prof. John Board Duke University Slides are derived from work by Profs. Tyler Bletsch and Andrew Hilton (Duke)
More informationProcess Management 1
Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Programmatically redirecting stdin, stdout, and stderr (Appendix) communication between processes via pipes Why?
More informationCS 140 Project 4 File Systems Review Session
CS 140 Project 4 File Systems Review Session Prachetaa Due Friday March, 14 Administrivia Course withdrawal deadline today (Feb 28 th ) 5 pm Project 3 due today (Feb 28 th ) Review section for Finals on
More informationThe Process Abstraction. CMPU 334 Operating Systems Jason Waterman
The Process Abstraction CMPU 334 Operating Systems Jason Waterman How to Provide the Illusion of Many CPUs? Goal: run N processes at once even though there are M CPUs N >> M CPU virtualizing The OS can
More informationProcesses COMPSCI 386
Processes COMPSCI 386 Elements of a Process A process is a program in execution. Distinct processes may be created from the same program, but they are separate execution sequences. call stack heap STACK
More informationCS 241 Data Organization Binary Trees
CS 241 Data Organization Binary Trees Brooke Chenoweth University of New Mexico Fall 2017 Binary Tree: Kernighan and Ritchie 6.5 Read a file and count the occurrences of each word. now is the time for
More information628 Lecture Notes Week 4
628 Lecture Notes Week 4 (February 3, 2016) 1/8 628 Lecture Notes Week 4 1 Topics I/O Redirection Notes on Lab 4 Introduction to Threads Review Memory spaces #include #include int
More informationComputer Systems Assignment 2: Fork and Threads Package
Autumn Term 2018 Distributed Computing Computer Systems Assignment 2: Fork and Threads Package Assigned on: October 5, 2018 Due by: October 12, 2018 1 Understanding fork() and exec() Creating new processes
More informationVector and Free Store (Pointers and Memory Allocation)
DM560 Introduction to Programming in C++ Vector and Free Store (Pointers and Memory Allocation) Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides
More informationProcess Management! Goals of this Lecture!
Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" (Appendix) communication between processes via pipes"
More informationLecture Notes on Memory Layout
Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationSection 2: Processes
September 7, 2016 Contents 1 Warmup 2 1.1 Hello World............................................ 2 2 Vocabulary 2 3 Problems 3 3.1 Forks................................................ 3 3.2 Stack Allocation.........................................
More informationUniversidad Carlos III de Madrid Computer Science and Engineering Department Operating Systems Course
Exercise 1 (20 points). Autotest. Answer the quiz questions in the following table. Write the correct answer with its corresponding letter. For each 3 wrong answer, one correct answer will be subtracted
More informationProject 3: Virtual Memory
Project 3: Virtual Memory Prof. Jin-Soo Kim ( jinsookim@skku.edu) TA Bak jin-yeong (dongdm@gmail.com) Go gyeong-min (gkm2164@gmail.com) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu
More information(In columns, of course.)
CPS 310 first midterm exam, 10/9/2013 Your name please: Part 1. Fun with forks (a) What is the output generated by this program? In fact the output is not uniquely defined, i.e., it is not always the same.
More informationLab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables
Lab#5 Due Wednesday, February 25, at the start of class Purpose: To develop familiarity with C++ pointer variables Introduction: In this lab, you will learn by experimentation the answers to some questions
More informationCS 550 Operating Systems Spring Process II
CS 550 Operating Systems Spring 2018 Process II 1 Recap: Process Informal definition: A process is a program in execution. Process is not the same as a program. Program is a passive entity stored in the
More informationMemory Corruption 101 From Primitives to Exploit
Memory Corruption 101 From Primitives to Exploit Created by Nick Walker @ MWR Infosecurity / @tel0seh What is it? A result of Undefined Behaviour Undefined Behaviour A result of executing computer code
More informationPrinceton University. Computer Science 217: Introduction to Programming Systems. Process Management
Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate
More informationAltering the Control Flow
Altering the Control Flow Up to Now: two mechanisms for changing control flow: Jumps and branches Call and return using the stack discipline. Both react to changes in program state. Insufficient for a
More informationA2 Design Considerations. CS161, Spring
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
More informationSection 4: Threads and Context Switching
CS162 September 19-20, 2017 Contents 1 Warmup 2 1.1 Hello World............................................ 2 2 Vocabulary 2 3 Problems 3 3.1 Join................................................ 3 3.2
More informationWeek 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430
Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationProcess Management 1
Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate Executing new programs Shell structure Why? Creating new processes and executing
More informationKurt Schmidt. October 30, 2018
to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed
More information377 Student Guide to C++
377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided
More informationSYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14
SYSTEM CALL IMPLEMENTATION CS124 Operating Systems Fall 2017-2018, Lecture 14 2 User Processes and System Calls Previously stated that user applications interact with the kernel via system calls Typically
More informationProcesses & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J
Processes & Threads Today! Process concept! Process model! Implementing processes! Multiprocessing once again Next Time! More of the same J The process model! Most computers can do more than one thing
More informationProcess Management! Goals of this Lecture!
Process Management! 1 Goals of this Lecture! Help you learn about:" Creating new processes" Programmatically redirecting stdin, stdout, and stderr" Unix system-level functions for I/O" The Unix stream
More informationBackground. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.
Background The Critical-Section Problem Background Race Conditions Solution Criteria to Critical-Section Problem Peterson s (Software) Solution Concurrent access to shared data may result in data inconsistency
More informationProcesses. CS439: Principles of Computer Systems January 30, 2019
Processes CS439: Principles of Computer Systems January 30, 2019 What We Know Operating system complexity increased over time in response to economic and technological changes The three roles did not show
More informationPrinceton University Computer Science 217: Introduction to Programming Systems. Process Management
Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate
More informationTDDB68 Lesson 1 Introduction to Pintos Assignments 00, 0, 1, 2
TDDB68 Lesson 1 Introduction to Pintos Assignments 00, 0, 1, 2 Mattias Eriksson 2010 mater@ida.liu.se Some slides by Viacheslav Izosimov 2007-2008 Outline Administration Introduction to Pintos Important
More informationThe Kernel Abstraction. Chapter 2 OSPP Part I
The Kernel Abstraction Chapter 2 OSPP Part I Kernel The software component that controls the hardware directly, and implements the core privileged OS functions. Modern hardware has features that allow
More informationAltering the Control Flow
Altering the Control Flow Up to Now: two mechanisms for changing control flow: Jumps and branches Call and return using the stack discipline. Both react to changes in program state. Insufficient for a
More informationProject 2: Shell with History1
Project 2: Shell with History1 See course webpage for due date. Submit deliverables to CourSys: https://courses.cs.sfu.ca/ Late penalty is 10% per calendar day (each 0 to 24 hour period past due). Maximum
More informationPipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University
Pipes and FIFOs Woo-Yeong Jeong (wooyeong@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Open Files in Kernel How the Unix kernel represents open files? Two descriptors
More informationAre branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process?
Processes and control flow Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? 1 Control Flow Processors do only one thing:
More informationCS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University
CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),
More informationIntroduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar
Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Processes in Unix, Linux, and Windows Unix pre-empted
More informationCMSC 313 Spring 2010 Exam 3 May 17, 2010
CMSC 313 Spring 2010 Exam 3 May 17, 2010 Name Score UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. There are no intentional syntax errors in any code provided with
More informationComputer 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 Name SID Login TA Name Section Time This is a closed book exam with one 2-sided page of notes
More informationChapter 17 vector and Free Store. Bjarne Stroustrup
Chapter 17 vector and Free Store Bjarne Stroustrup www.stroustrup.com/programming Overview Vector revisited How are they implemented? Pointers and free store Allocation (new) Access Arrays and subscripting:
More informationA heap, a stack, a bottle and a rack. Johan Montelius HT2017
Introduction A heap, a stack, a bottle and a rack. Johan Montelius HT2017 In this assignment you re going to investigate the layout of a process; where are the different areas located and which data structures
More informationCS 201. Processes. Gerson Robboy Portland State University
CS 201 Processes Gerson Robboy Portland State University Review Definition: A process is an instance of a running program. One of the most fundamental concepts in computer science. Not the same as program
More informationIntroduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras
Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week 03 Lecture 12 Create, Execute, and Exit from a Process
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Winter 2009 Lecture 7 Introduction to C: The C-Level of Abstraction CSE 303 Winter 2009, Lecture 7 1 Welcome to C Compared to Java, in rough
More informationProcesses (Intro) Yannis Smaragdakis, U. Athens
Processes (Intro) Yannis Smaragdakis, U. Athens Process: CPU Virtualization Process = Program, instantiated has memory, code, current state What kind of memory do we have? registers + address space Let's
More informationChapter 17 vector and Free Store
Chapter 17 vector and Free Store Bjarne Stroustrup www.stroustrup.com/programming Overview Vector revisited How are they implemented? Pointers and free store Allocation (new) Access Arrays and subscripting:
More informationContents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)
Pipes and FIFOs Prof. Jin-Soo Kim( jinsookim@skku.edu) TA JinHong Kim( jinhong.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents IPC (Inter-Process Communication)
More informationExceptional Control Flow Part I Oct. 17, 2002
15-213 The course that gives CMU its Zip! Exceptional Control Flow Part I Oct. 17, 2002 Topics Exceptions Process context switches Creating and destroying processes class16.ppt Control Flow Computers do
More informationThreads Tuesday, September 28, :37 AM
Threads_and_fabrics Page 1 Threads Tuesday, September 28, 2004 10:37 AM Threads A process includes an execution context containing Memory map PC and register values. Switching between memory maps can take
More informationUnderstanding Pointers
Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer
More informationCS61 Scribe Notes Date: Topic: Fork, Advanced Virtual Memory. Scribes: Mitchel Cole Emily Lawton Jefferson Lee Wentao Xu
CS61 Scribe Notes Date: 11.6.14 Topic: Fork, Advanced Virtual Memory Scribes: Mitchel Cole Emily Lawton Jefferson Lee Wentao Xu Administrivia: Final likely less of a time constraint What can we do during
More informationControl Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow
Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes Control Flow Computers do Only One Thing From startup
More informationThe Art and Science of Memory Allocation
Logical Diagram The Art and Science of Memory Allocation Don Porter CSE 506 Binary Formats RCU Memory Management Memory Allocators CPU Scheduler User System Calls Kernel Today s Lecture File System Networking
More informationProject 2 Overview: Part A: User space memory allocation
Project 2 Overview: Once again, this project will have 2 parts. In the first part, you will get to implement your own user space memory allocator. You will learn the complexities and details of memory
More informationCSCI 237 Sample Final Exam
Problem 1. (12 points): Multiple choice. Write the correct answer for each question in the following table: 1. What kind of process can be reaped? (a) Exited (b) Running (c) Stopped (d) Both (a) and (c)
More informationMidterm Exam CPS 210: Operating Systems Spring 2013
Your name: Sign for your honor: Midterm Exam CPS 210: Operating Systems Spring 2013 The last page of this exam is a list of terms used in this class, and whose meanings you should know. You may detach
More informationProcesses. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware
es CS 217 Operating System Supports virtual machines Promises each process the illusion of having whole machine to itself Provides services: Protection Scheduling Memory management File systems Synchronization
More informationOS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed
Process Management CS 537 Lecture 3: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units
More informationFirst Midterm Exam Solutions October 1, 2018 CS162 Operating Systems
University of California, Berkeley College of Engineering Computer Science Division EECS Fall 2018 Ion Stoica First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems Your Name: SID AND 162
More informationFall 2015 COMP Operating Systems. Lab #3
Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute
More information