Project 2: User Programs Abdelmounaam Rezgui Acknowledgment: The content of some slides is partly taken from Josh Wiseman’s presentation.

Slides:



Advertisements
Similar presentations
Christo Wilson Project 2: User Programs in Pintos
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
CSCC69: Operating Systems
1 Pintos Project #3 Virtual Memory The following slides were created by Xiaomo Liu and others for CS 3204 Fall And Modified by Nick Ryan for Spring.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Jaishankar Sundararaman
CS 4284 Systems Capstone Project 2 Hints Slides created by Jaishankar Sundararaman.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
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.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
CSE 451 Section 4 Project 2 Design Considerations.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP229 - System Software Edition 1.1,
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.
Creating and Executing Processes
Project 2: User Programs
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Project 2: Initial Implementation Notes Tao Yang.
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.
System calls for Process management
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Operating Systems Process Creation
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Processes and Virtual Memory
Nachos Lecture 2 Xiaorui Sun. Phase 2 You have got one machine (machine package) You have to implements the incomplete OS (userprog package) Run programs.
Process Management Azzam Mourad COEN 346.
Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Pintos project 3: Virtual Memory Management
Project 2: User Programs Presented by Min Li 26 Feb 2009.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
System calls for Process management Process creation, termination, waiting.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Chapter 9: Virtual Memory – Part I
Jaishankar Sundararaman
Unix Process Management
Processes in Unix, Linux, and Windows
System Structure and Process Model
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Genesis: From Raw Hardware to Processes
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Tutorial: The Programming Interface
Lecture 6: Multiprogramming and Context Switching
CSCI 380: Operating Systems William Killian
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Section 2 Processes January 27rd, 2017 Taught by Joshua Don.
CSE 153 Design of Operating Systems Winter 2019
Presentation transcript:

Project 2: User Programs Abdelmounaam Rezgui Acknowledgment: The content of some slides is partly taken from Josh Wiseman’s presentation

2 Overview Objective: Enable user programs to run and interact with the OS via system calls Directories: userprog/ threads/ examples/

3 Using the File System -1- NOT the focus of this project User programs are loaded from the FS Many system calls deal with the FS (e.g., open(), read(), write()) Simple file system provided in the filesys directory Look at: filesys.h and file.h Limit is 16 files No subdirectories

4 Using the File System -2- Create a (simulated) disk: pintos-mkdisk img-file = filename for disk (usually “fs.dsk”) size = disk capacity, MB Format disk pintos -f -q -f = format, -q = quit after boot Copy to disk: Pintos -p -a -- -q -p = source file, -a = filename on disk Run program: Pintos run $ make check: will build a disk for you

5 Sample user programs In examples/ cat, echo, halt, hex-dump, ls, shell You should be able to write and run your own programs Create a test disk Copy programs to the test disk

6 Requirements 1) Argument passing 2) System calls 3) Process termination 4) Deny writes to executables 5) DESIGNDOC

7 Getting Started In the default version, programs will crash To get simple programs to run: *esp = PHYS_BASE – 12; This will NOT make argument passing work

8 Argument Passing -1- pgm.c main(int argc, char *argv[]) { … } $ pintos run ‘pgm alpha beta’ argc = 3 argv[0] = “pgm” argv[1] = “alpha” argv[2] = “beta” Motivation: kernel creates first process one process creates another $ pintos run ‘pgm alpha beta’ You may: use strtok_r() to parse the command line assume cmd line length < 4KB

9 Argument Passing -2-

10 Argument Passing -3-

11 Argument Passing -4-

12 Argument Passing -5-

13 System Calls -1- User programs make system calls E.g., open(), close(), exit(), halt(), … Implement system calls: Process control: exit(), exec(), and wait() Filesystem calls: create(),open(),close(),read(),write(),seek(), tell(),filesize(),remove() halt()

14 System Calls -2- The OS deals with software exceptions (called “internal interrupts” in the x86) SEs are events that occur in program code. They may be: Errors: e.g., page faults, division by 0 System Calls SEs don’t execute in interrupt context i.e., intr_context() == false In the 80x86 arch, the ‘int’ instruction is used to make system calls In Pintos, user programs invoke ‘int $0x30’ to make system calls

15 System Calls -3- A system call has: System call number (possibly) arguments System call numbers are in: lib/syscall-nr.h When syscall_handler() gets control: System calls that return a value () must modify f->eax

16 System Calls -4- Filesystem calls You must decide how to implement file descriptors O(n) data structures for file descriptors are OK For this project, access granularity is the entire file syst. Use ONE lock for the entire file system write(1, …) writes to the console. Use putbuf(). read(0, …) reads from the stdin (keyboard). Use kbd_getc().

17 System Calls -5- exec(const char *cmd_line) Runs ‘cmd_line’, passes args, returns pid exit() retains error codes for wait() main() { pid_t p; p = exec(“cp file1 file2”); … }

18 System Calls -6- wait(pid_t pid) Waits for process pid to die and returns the status that pid returned to exit() Returns -1 if pid was killed by the kernel pid is not a child Wait has already been successfully called

19 System Calls -7- Parent may or may not wait for its child Parent may call wait() after child terminates! Implement process_wait() in process.c Then, implement wait() in terms of process_wait() Conditions and semaphores will help Think about what semaphores may be used for and how they must be initialized main() { int status; … status = 5; exit(status); } main() { int i; pid_t p; p = exec(“pgm a b”); i = wait (p); … /* i must be 5 */ } pgm.c

20 Process Termination Record the argument passed to the exit() syscall When a user process exits: printf(“%s: exit(%d)\n”,…) ALL programs call exit() unless, of course, if they're terminated Returning from main implicitly calls exit() _start() is { exit( main(…) ); }

21 Virtual Memory Layout -1- Stack does NOT grow until Project 3 Heap never grows Uninitialized means “zero-initialized” UVM is per-process A user program accesses only its UVM

22 Virtual Memory Layout -2- If it attempts to access KVM Page fault Kernel threads access KVM and the UVM of the running user process In this project, this image is ALREADY set up for you. You only have to query the page table to see which pages are mapped

23 Memory Access -1- Kernel needs to access memory through pointers given by a user program user-provided pointers may be invalid point to unmapped VM point to KVM address space How to handle this ?

24 Memory Access -2- Two options: verify the validity of a user-provided pointer, then dereference it – STRONGLY RECOMMENDED! dereference and handle during page fault Check only that user pointer points below PHYS_BASE Dereference it If it causes a page fault, handle it You need to modify the code for page_fault()

25 Memory Access -3- In BOTH cases: Graceful termination Misbehaving processes must be killed Orderly shutdown No resource leaks E.g., release locks, free allocated memory pages, etc. Data may span page boundaries

26 Denying Writes to Executables You may use: file_deny_write() to prevent writes to an open file file_allow_write() re-enables them (if no other process has already denied them) If a file is closed, writes are re-enabled.

27 Misc Read Section 4.2 (page 51) (Suggested Order of Implementation) in Pintos documentation Do not forget the Design Document Good Luck !