proc - Classic Processes (CSE 422S) Dante Cannarozzi...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Classic Processes (CSE 422S) Dante Cannarozzi Washington University [email protected] www.cse.wustl.edu/~djc2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 -Ken Wong, 09/14/09 fork, exec and the shell (1) Your interactive shell (tcsh, bash) interprets commands Shell processing of ‘fib 10’ » Shell looks for the ‘fib’ executable in a directory listed in the PATH environment variable A e.g., “.:/usr/home/kenw/bin:/usr/bin:/usr/local/bin” » Forks a copy of the shell; i.e., creates a child process » Child redirects stdout to the file ‘fib10.out’ » Child execs ‘fib’ passing in command-line arguments ‘fib’ process replaces the shell’s child process » Parent shell waits for ‘fib’ process to terminate » Display prompt after ‘fib’ terminates Example: Interactive Commands > fib 10 > fib10.out > fib 2000 > fib2000.out & Run in the background
Background image of page 2
3 -Ken Wong, 09/14/09 fork, exec and the shell (2) Shell processing of ‘fib 2000’ » Processing is the same as for ‘fib 10’ except that parent does not wait for child to terminate Extended Example: » Shell later waits for child > fib 10 > fib10.out > fib 2000 > fib2000.out & > fib 3000 > fib3000.out & . . . > wait $! # last bg proc Fundamental Abstraction: The Process » Traditional Process : The process executes a single sequence of instructions in an address space » The program counter (PC) tracks the sequence of instructions » Modern Process : Multiple control paths sh sh fork sh fib exec
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 -Ken Wong, 09/14/09 waitpid pid_t waitpid(pid_t pid, int *status, int option); » Unlike wait(2), waitpid doesn’t have to block wait(2) blocks until one of its children terminates pid values » pid == -1: Wait for any direct child to terminate » pid > 0: Wait for child whose PID equals pid » pid == 0: Wait for any child whose PGID equals the PGID of process pid » pid < -1: Wait for any child whose PGID= abs(pid) *status » Contains exit status, signal number, and flags options » Controls semantics of waitpid
Background image of page 4
5 -Ken Wong, 09/14/09 waitpid options options = 0 » No special handling options = WNOHANG » Don’t block if child is not available and return 0 » Ex: rc = waitpid(pid, &status, WNOHANG); if (rc == -1) { . . . error . . . } else if (rc == 0) { . . . no child available . . .} else { . . . rc should equal pid . . . } options = WUNTRACED » Return status of child if stopped child and status has not already been returned (assumes job control support)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 -Ken Wong, 09/14/09 Examining waitpid ‘status’ Contains exit status, signal number, and flags WIFEXITED(status) » True if child terminated normally » Ex: printf(“exit = %d\n”, WEXITSTATUS(status)); WIFSIGNALED(status) » True if child terminated and didn’t catch signal » Ex: printf(“signo = %d\n”, WTERMSIG(s)); WIFSTOPPED(status) » True if child is STOPPED » Ex: printf(“signo = %d\n”, WSTOPSIG(s));
Background image of page 6
7 -Ken Wong, 09/14/09 Two CPU Intensive BG Processes fib 2000 fib 3000 Unix Kernel high-priority clock interrupts Scheduler Idle Process Time exit exit if shell is running if no other runnable processes quantum expired shell waiting for line
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Process Run States (Simplified) New Ready Running Waiting Zombie Preempt I/O or Event Wait Dispatch
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/13/2009.

Page1 / 34

proc - Classic Processes (CSE 422S) Dante Cannarozzi...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online