16 Process Control

16 Process Control - !"#"$% CMSC 216 Introduction...

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

View Full Document Right Arrow Icon
!"#"$$ $ CMSC 216 Introduction to Computer Systems Lecture 16 Process Control and System-Level I/O Jan Plane & Pete Keleher {jplane,keleher}@cs.umd.edu Administrivia • Project 4 – write and test each function!!! • Exam – Tuesday, April 5 CMSC 216 - Wood, Sussman, Herman, Plane 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
!"#"$$ P ROCESS C ONTROL ( CONT .) Sections 8.2-8.5, Bryant and O'Hallaron CMSC 216 - Wood, Sussman, Herman, Plane 3 Reaping child processes • When a process exits, it is still tracked by the kernel (remember the termination process state?) • Processes are released from the process table only when their parent reaps the terminated child; until this happens, the terminated process is called a zombie • A parent can release its zombie children from the process table via either the wait() or waitpid () system calls • If the parent terminates before the child, the child is orphaned, and then adopted by the init process (pid #1); init will reap children as soon as they terminate CMSC 216 - Wood, Sussman, Herman, Plane 4
Background image of page 2
!"#"$$ ' wait() system calls • Can be used to obtain the exit status of the reaped child (or not, if you don't care) pid_t wait(int *status); – requires <sys/types.h> and <sys/wait.h> – pass in a pointer to an int (or NULL ) that will be populated by the status of the reaped process – will reap any single terminated child blocking wait; does not return until a terminated child exists (if a child exists) – returns -1 on error (e.g., no unwaited-for children exist) – returns pid of reaped process on success CMSC 216 - Wood, Sussman, Herman, Plane 5 wait() system calls, cont. pid_t waitpid(pid_t pid, int *status, int options); – will wait on one specified process pid is pid of the child process options is a number formed from the bitwise OR of several flags (or just 0); WNOHANG is the most useful of these flags (doesn't block) CMSC 216 - Wood, Sussman, Herman, Plane 6
Background image of page 3

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

View Full DocumentRight Arrow Icon
!"#"$$ ! wait()
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

16 Process Control - !&quot;#&quot;$% CMSC 216 Introduction...

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

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