15-213/18-243 Intro to Computer Systems by btan with reference to Spring 10’s slides.

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

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.
Processes Topics Process context switches Creating and destroying processes CS 105 “Tour of the Black Holes of Computing!”
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.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
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.
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
CSE 451 Section 4 Project 2 Design Considerations.
Processes, Signals, I/O, Shell lab
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: 10/21/2013 Tommy Klein Section B.
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.
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.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
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).
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Processes & Threads Emery Berger and Mark Corner University.
Process. Processes A process is an abstraction for sequence of operations that implement a computation/program. A process may be manipulated, suspended,
Operating Systems Chapter 2
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CS 241 Section Week #2 9/9/10. 2 Topics This Section MP1 issues MP2 overview Process creation using fork()‏ Debugging tools: valgrind, gdb.
CE Operating Systems Lecture 10 Processes and process management in Linux.
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.
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.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
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.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Carnegie Mellon 1 Processes, Signals, I/O, Shell Lab : Introduction to Computer Systems Recitation 9: Monday, Oct. 21, 2013 Marjorie Carlson Section.
Process Management Azzam Mourad COEN 346.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
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.
System calls for Process management Process creation, termination, waiting.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
Section 8: Processes What is a process Creating processes Fork-Exec
Unix Process Management
UNIX PROCESSES.
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.
Tarek Abdelzaher Vikram Adve Marco Caccamo
Processes in Unix, Linux, and Windows
Processes in Unix, Linux, and Windows
System Structure and Process Model
CS 105 “Tour of the Black Holes of Computing!”
Processes Prof. Ikjun Yeom TA – Mugyo
CS 105 “Tour of the Black Holes of Computing!”
Jonathan Walpole Computer Science Portland State University
CS 105 “Tour of the Black Holes of Computing!”
Lecture 6: Multiprogramming and Context Switching
Exceptional Control Flow
Processes in Unix, Linux, and Windows
CS510 Operating System Foundations
Presentation transcript:

15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides

 Cachelab due tomorrow 11:59pm  Proclab out tomorrow  Today’s recitation will be on Process Control and Signal Handling News

 What is a program?  Written according to a specification that tells users what it is supposed to do  A bunch of data and instructions stored in an executable binary file  Stateless since binary file is static Processes

 What is a process?  A running instance of a program in execution  One of the most profound ideas in CS  A fundamental abstraction provided by the OS  Single thread of execution (linear control flow) ….  … until you create more threads (later in the course)  Stateful:  Full set of private address space and registers  Other state like open file descriptors and etc. Processes

 Four basic process control functions  fork()  exec*() and other variants such as execve()  But they all fundamentally do the same thing  exit()  wait() Standard on all UNIX-based systems Don’t be confused: Fork(), Exit(), Wait() are all wrappers provided by CSAPP Processes

 fork()  Creates or spawns a child process  OS creates an exact duplicate of parent’s state:  Virtual address space (memory), including heap and stack  Registers, except for the return value (%eax/%rax)  File descriptors but files are shared  Result  Equal but separate state  Returns 0 for child process but child’s PID for parent Processes

 exec*()  Replaces the current process’s state and context  Provides a way to load and run another program  Replaces the current running memory image with that of new program  Set up stack with arguments and environment variables  Start execution at the entry point  The newly loaded program’s perspective: as if the previous program has not been run before  It is actually a family of functions  man 3 exec Processes

 exit()  Terminates the current process  OS frees resources such as heap memory and open file descriptors and so on…  Reduce to a zombie state =]  Must wait to be reaped by the parent process (or the init process if the parent died)  Reaper can inspect the exit status Processes

 wait()  Waits for a child process to change state  If a child terminated, the parent “reaps” the child, freeing all resources and getting the exit status  Child fully “gone”   For details: man 2 wait Processes

 What are the possible output (assuming fork succeeds) ?  Child!, Parent!  Parent!, Child!  How to get the child to always print first? Processes (Concurrency) pid_t child_pid = fork(); if (child_pid == 0){ /* only child comes here */ printf(“Child!\n”); exit(0); } else{ printf(“Parent!\n”); }

int status; pid_t child_pid = fork(); if (child_pid == 0){ /* only child comes here */ printf(“Child!\n”); exit(0); } else{ waitpid(child_pid, &status, 0); printf(“Parent!\n”); } Processes (Concurrency)  Waits til the child has terminated. Parent can inspect exit status of child using ‘status’  WEXITSTATUS(status)  Output always: Child!, Parent!

Processes (Concurrency) int status; pid_t child_pid = fork(); char* argv[] = {“ls”, “-l”, NULL}; char* env[] = {…, NULL}; if (child_pid == 0){ /* only child comes here */ execve(“/bin/ls”, argv, env); /* will child reach here? */ } else{ waitpid(child_pid, &status, 0); … parent continue execution… }  An example of something useful.  Why is the first arg “ls”?  Will child reach here?

 Four basic States  Running  Executing instructions on the CPU  Number bounded by number of CPU cores  Runnable  Waiting to be running  Blocked  Waiting for an event, maybe input from STDIN  Not runnable  Zombie =]  Terminated, not yet reaped Processes

 Primitive form of interprocess communication  Notify a process of an event  Asynchronous with normal execution  Come in several types  man 7 signal  Sent in various ways  Ctrl+C, Ctrl+Z  kill()  kill utility Signals

 Handling signals  Ignore  Catch and run signal handler  Terminate, and optionally dump core  Blocking signals  sigprocmask()  Waiting for signals  sigsuspend()  Can’t modify behavior of SIGKILL and SIGSTOP  Non-queuing Signals

 Signal handlers  Can be installed to run when a signal is received  The form is void handler(int signum){ …. }  Separate flow of control in the same process  Resumes normal flow of control upon returning  Can be called anytime when the appropriate signal is fired Signals

Signals (Concurrency) ….install sigchld handler… pid_t child_pid = fork(); if (child_pid == 0){ /* child comes here */ execve(……); } else{ add_job(child_pid); } void sigchld_handler(int signum) { int status; pid_t child_pid = waitpid(-1, &status, WNOHANG); if (WIFEXITED(status)) remove_job(child_pid); } What could happen here? How to solve this issue? Block off SIGCHLD signal at the appropriate places. You’d have to think of it yourself.

 A series of puzzles on process control and signal handling  Correct use of system functions  Test your understanding of the concepts  Should not need to write a lot of code  5 Style points – Yes, we will read your code  Details in the handout ProcLab

 Thank you Q & A