UC Santa Barbara Project 1 Discussion Bryce Boe 2011/04/12.

Slides:



Advertisements
Similar presentations
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Advertisements

15-213, Fall 06 Outline Shell Lab Processes Signals.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
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.
CS Lecture 15 Outline Process Management System calls – exec() – chdir() – system() – nice() – Accessing User and Group IDs – Redirection Lecture.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Shell (Part 1). Process r A process is an instance of an application running r If there are two instances of an application running then there are two.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Operating Systems Chapter 2
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Creating and Executing Processes
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CE Operating Systems Lecture 10 Processes and process management in Linux.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
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.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
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,
2.1 Processes  process = abstraction of a running program.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Process Management Azzam Mourad COEN 346.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
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.
OS Labs 2/25/08 Frans Kaashoek MIT
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
2.1 Processes  process = abstraction of a running program  multiprogramming = CPU switches from running program to running program  pseudoparallelism.
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
Unix Process Management
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Example questions… Can a shell kill itself? Can a shell within a shell kill the parent shell? What happens to background processes when you exit from.
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
Fork and Exec Unix Model
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
2.1 Processes process = abstraction of a running program
Operating Systems Lecture 6.
Chapter 3: Processes.
2/25/08 Frans Kaashoek MIT OS abstractions 2/25/08 Frans Kaashoek MIT
Tutorial: The Programming Interface
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Intro to the Shell with Fork, Exec, Wait
Presentation transcript:

UC Santa Barbara Project 1 Discussion Bryce Boe 2011/04/12

UC Santa Barbara Schedule Announcements – Send me with teams and team name – Demo times (4/26, 5/17, 6/7 from 3-7) – Anonymous Feedback Project 1 – Simple Shell (35 minutes) – Lottery Scheduler (15 minutes) Bryce Boe – CS170 S11

UC Santa Barbara Project 1- Two Parts Simple Shell – Read input from standard in – Handle special cases with >, <, |, & – All shell output to stdout – No debugging output Minix Lottery Scheduling – Piggyback lottery scheduler for user processes on existing priority scheduler – Add system call to change number of tickets for a process Bryce Boe – CS170 S11

UC Santa Barbara What is a shell? Control program execution Manage program input and output Control working directory Switch between foreground and background processes Bryce Boe – CS170 S11

UC Santa Barbara System Calls You Will Need fork – copy current process including all file descriptors exec – replace running process with code from program (file descriptors persist) waitpid – current process waits until pid terminates pipe – create memory mapped file dup/dup2 – update process file descriptor numbers Bryce Boe – CS170 S11

UC Santa Barbara Great C Resource Opengroup.org Google search to find command: – fork site:opengroup.org Bryce Boe – CS170 S11

UC Santa Barbara pid_t fork(void) int pid; switch (pid = fork()) { case 0: /* child process */ break; case -1: /* error */ break; default: /* parent process when pid > 0 */ } Bryce Boe – CS170 S11

UC Santa Barbara int execvp(const char *file, char *const argv[]); char *argv[] = {“ls”, “-la”, “/tmp”, NULL} if (execvp(argv[0], argv)) /* exec failed, maybe file not found */ else /* guaranteed to never enter here */ Bryce Boe – CS170 S11

UC Santa Barbara pid_t waitpid(pid_t pid, int *stat_loc, int options); pid_t child_pid; int status; if ((child_pid = fork() != 0) { waitpid(child_pid, &status, 0); printf("%d\n", status); /* should be 1 */ } else { exit(1); } Bryce Boe – CS170 S11

UC Santa Barbara int pipe(int fildes[2]); int fildes[2]; char buf[BUFSIZ]; if (pipe(fildes)) { /* error */ } if (fork()) { close(fildes[0]); /* close read end */ write(fildes[1], “foobar\n”, 7); } else { close(fildes[1]); /* close write end */ read(fildes[0], buf, 7); /* reads foobar */ } Bryce Boe – CS170 S11

UC Santa Barbara int dup2(int fildes, int fildes2); /* redirect stdout to a file */ int fp; fp = open("/tmp/somefile", 'w'); /* 3 */ close(STDOUT_FILENO); /* close 0 */ dup2(fp, STDOUT_FILENO); /* clone 3 to 0 */ close(fp); /* close 3 */ Bryce Boe – CS170 S11

UC Santa Barbara Parsing Commands Command input represents a grammar – Begin -> command (‘ ’ file)? ‘&’? – Begin -> command (‘<‘ file)? ‘|’ Extended – Extended -> command (‘>’ file)? ‘&’? – Extended -> command ‘|’ Extended Must parse the commands properly and create the execution chain Bryce Boe – CS170 S11

UC Santa Barbara Process Tree Creation Questions How do we launch a single process and have the shell wait? – What about I/O redirection? How do we launch two processes with a pipe between them? – Which process does the shell wait on? – What file descriptors does each process inherit? Bryce Boe – CS170 S11

UC Santa Barbara Current Minix Scheduler Priority scheduler – 1. Kernel tasks (system task / clock task) – 2. Device drivers – 3. Server processes – 4. User processes – Last. Idle process Implemented with 16 queues Highest priority process in ‘ready’ state is run Bryce Boe – CS170 S11

UC Santa Barbara Running Processes Each process has a quanta (total time to run) Higher priority queues may provide more quanta Processes run until either – They give up the CPU when making a system call such as IO (return to the head of their queue when ‘ready’ again – Their quanta is exhausted (return to end of current queue, higher queue, or lower queue depending) Bryce Boe – CS170 S11

UC Santa Barbara Switching Queues If there are no other “ready” processes when a process exhausts its entire quanta twice the process moves up to a higher priority queue If there other other “ready” processes when a process exhausts its entire quanta twice the process moves down to a lower priority queue Processes can request a change via the nice system call Bryce Boe – CS170 S11

UC Santa Barbara Priority Scheduler Questions Which is given priority IO bound or CPU bound? Can high priority processes starve low priority processes? What happens if a device driver or server (high priority) enters a CPU bound infinite loop? Bryce Boe – CS170 S11

UC Santa Barbara Lottery Scheduler Each (user) process is given 5 tickets to start At each scheduling decision: – chose a random number between 0 and the total number of assigned tickets - 1 – schedule process “holding” that ticket Processes can modify their priority via setpriority(ntickets) (max 100 tickets) Bryce Boe – CS170 S11

UC Santa Barbara Integration Keep it simple Only user processes are required to use the lottery scheduler Do not need to worry about breaking the nice system call for user processes Do not need to worry about handling the setpriority system call for kernel/device/server processes Bryce Boe – CS170 S11

UC Santa Barbara To consider How do we find the process that is elected? Incrementally test small changes to ensure you haven’t broke the scheduler Write minix user programs to test functionality – Equivalent processes running concurrently should complete in the same time – If process A has twice the priority of process B it should complete in approximately half the time Bryce Boe – CS170 S11

UC Santa Barbara Good luck! Questions? Bryce Boe – CS170 S11