{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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)
Image of page 5

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

View Full Document Right 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));
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
Image of page 7

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

View Full Document Right Arrow Icon
8 -Ken Wong, 09/14/09 Process Run States (Simplified) New Ready Running Waiting Zombie Preempt
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern