Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.

Slides:



Advertisements
Similar presentations
Recitation 8 (Nov. 1) Outline Process & job control Lab 5 Reminder Lab 5: Due Thursday Minglong Shao Office hours: Thursdays 5-6PM.
Advertisements

Operating Systems Lecture 7.
Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Carnegie Mellon 1 Exceptional Control Flow : Introduction to Computer Systems Recitation 9: Monday, October 21 st, 2013 Ian Hartwig Section E.
15-213, Fall 06 Outline Shell Lab Processes Signals.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
The Process Model.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
CS Lecture 16 Outline Inter-process Communication (IPC) – Pipes – Signals Lecture 161CS Operating Systems 1.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Section A (March 14) Outline Exceptions Process Signals Non-local jumps Reminders Lab4: Due Next Thursday TA: Kun Gao Shamelessly Modified from Minglong.
Processes, Signals, I/O, Shell lab
CSc 352 Signal Handling in Unix Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
University of Pennsylvania 9/12/00CSE 3801 Multiprogramming CSE 380 Lecture Note 3.
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: 10/21/2013 Tommy Klein Section B.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
UNIX Signals Bach 7.2 Operating Systems Course The Hebrew University Spring 2010.
Introduction to Processes CS Intoduction to Operating Systems.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
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,
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.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
System calls for Process management
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
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.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes and Threads.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Process Models, Creation and Termination Reference –text: Tanenbaum ch. 2.1.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
Operating Systems Process Creation
1 Signals (continued) CS 241 April 9, 2012 University of Illinois.
UNIX Signals * POSIX-Defined Signals * Signaling Processes * Signal Mask * sigaction * kill and sigaction * alarm * Interval Timers * POSIX.1b Timers *
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
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.
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: Monday, Oct. 21, 2013 Marjorie Carlson Section.
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
System calls for Process management Process creation, termination, waiting.
1 Exceptional Control Flow Ⅱ. 2 Outline Kernel Mode and User Mode Process context switches Three States of Processes Context Switch System Calls and Error.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
CSE 451: Operating Systems Section 6 Project 2b. Midterm  Scores will be on Catalyst and midterms were handed back on Friday(?) in class  Talk to Ed,
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
Recitation 7 (Oct. 25) Outline Minglong Shao Office hours: Reminders
Unix Process Management
Processes A process is a running program.
Process Models, Creation and Termination
Cs561 Presenter: QIAOQIAO CHEN Spring 2012
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS 105 “Tour of the Black Holes of Computing!”
Exceptional Control Flow
CS510 Operating System Foundations
Lab 6: Process Management
Process Description and Control in Unix
System Programming: Process Management
Presentation transcript:

Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla

Outline ✤ Midterm Overview ✤ Processes ✤ Signals ✤ Shell Lab Overview ✤ Cheating Policy Reminder

Midterm Overview ✤ Average: 54/71 ✤ Pick up from ECE Course Hub in HH 1112 ✤ Alternate solution to assembly question found ✤ Regrade requests accepted until Wednesday ✤ Question?

Processes

✤ What is a process? ✤ An instance of a program in execution ✤ A Great Idea in Computer Science ✤ Ubiquitous on multitasking systems ✤ Fundamental abstraction provided by the OS ✤ Single thread of execution (control flow) ✤ Full, private memory space and registers ✤ Various other state (file descriptors, etc.)

Processes ✤ Four basic process control functions ✤ fork() ✤ exec() ✤ exit() ✤ wait() ✤ Standard on all Unix systems

fork() ✤ Creates a process (more like mitosis than birth) ✤ Parent and child are exactly alike ✤ Except for return value (%eax) ✤ Equal, but private: ✤ Threads of execution ✤ Registers ✤ Memory ✤ File descriptors (note: files, however, are shared)

exec() ✤ Replaces process ✤ No processes created ✤ New process (mostly) unaware of old state ✤ How programs are run ✤ Replace memory image with new program ✤ Set up stack with arguments ✤ Start execution at the entry point (main) ✤ Actually a family of functions ✤ man 3 exec

exec() Example Code int rc = fork(); if (rc == 0) { printf( “ child\n ” ); execl( “ /bin/echo ”, “ /bin/echo ”, “ sup! ”, NULL); exit(EXIT_FAILURE); }printf( “ parent\n ” ); Output child sup! parent Any other possibilities?

exit() ✤ Terminates a process ✤ OS frees resources used by the process ✤ Tiny leftover data ✤ Zombie state ✤ Exit status for parent ✤ Must be freed (reaped)

wait() ✤ Blocks until child process changes state ✤ Reaps child if it terminated ✤ Frees all remaining resources and gets exit status ✤ Can be used for synchronization ✤ Lots of details ✤ man 2 wait

wait() Example Code int rc = fork(); if (rc == 0) { printf( “ child\n ” ); execl( “ /bin/echo ”, “ /bin/echo ”, “ sup! ”, NULL); exit(EXIT_FAILURE); }int status; waitpid(rc, &status, 0); printf( “ child status %d\n ”, WEXITSTATUS(status)); Output child sup! child status 0 Any other possibilities? Take a look at:

States ✤ Running ✤ Executing instructions on the CPU ✤ Number bounded by the number of CPU cores ✤ Runnable ✤ Waiting to be running ✤ Blocked ✤ Waiting for an event ✤ Not runnable ✤ Zombie ✤ Terminated but not yet reaped

Signals

✤ Primitive form of interprocess communication ✤ Notify process of an event ✤ Asynchronous with normal execution ✤ Several types ✤ man 7 signal ✤ Sent in various ways ✤ ^C, ^Z, ^\ ✤ kill command ✤ kill system call

Signals ✤ What to do when receiving a signal ✤ Ignore ✤ Catch and run signal handler ✤ Terminate ✤ man sigaction ✤ Blocking ✤ man sigprocmask ✤ Can’t modify behavior of SIGKILL and SIGSTOP ✤ Signals don’t queue

Signals ✤ Signal Handlers ✤ Can be installed to run when a signal is received ✤ Type is “void (*sa_handler)(int)” ✤ Separate control flow in the same process ✤ Resumes control flow on return ✤ Signal handlers can be called anytime

Signals ✤ Interesting signals ✤ SIGKILL – force kill a process ✤ SIGINT – kill a process ✤ SIGSTOP and SIGCONT – suspend and resume a process ✤ SIGCHLD – child changed state ✤ SIGSEGV – everyone knows this

Shell Lab

✤ Write a not-so-basic shell ✤ Fork and execute a new program ✤ Wait for foreground jobs ✤ Support background jobs ✤ React to changes in child state ✤ Input and output redirection ✤ ls > ls_out and wc < filename ✤ Many different designs ✤ Some much better than others

Shell Lab Tips ✤ Read the code we’ve given you. ✤ There is a lot of stuff you don’t need to write for yourself. ✤ It’s a good example of the kind of code we expect from you ✤ If you find yourself using sleep() as a way of avoiding race conditions, you are doing it VERY wrong. We will dock performance points for this. ✤ You should only use it for performance to avoid your code having to execute useless instructions. Your code should still work if we remove calls to sleep. ✤ Read the spec carefully and start early!

Shell Lab Hazards ✤ Race Conditions ✤ Hard to debug so start early ✤ Reaping zombies ✤ Again, race conditions ✤ Fiddle with signals ✤ Waiting for foreground job ✤ One of the only places where sleep is acceptable (though you don’t NEED it)

Cheating Policy Reminder ✤ Don’t do it. ✤ Two students caught by Moss have received R’s and could potentially be kicked out of their program ✤ Two more cases are currently looked into ✤ Never worth it.

Questions?