1 / 10

Chapter 8 Process Control

Chapter 8 Process Control. Chien -Chung Shen CIS, UD cshen@cis.udel.edu. Introduction. Process creation, execution, and termination IDs of a process. Process Identifiers. Every process has a unique process ID

yale
Télécharger la présentation

Chapter 8 Process Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 8Process Control Chien-Chung Shen CIS, UD cshen@cis.udel.edu

  2. Introduction • Process creation, execution, and termination • IDs of a process

  3. Process Identifiers • Every process has a unique process ID • often used as a piece of other identifiers to guarantee uniqueness, e.g., unique filenames • Special processes • ID 0: scheduler ([z]sched, swapper, etc.) • ID 1: init (invoked by the kernel at the end of the bootstrap procedure) • ID 2: page demon (for virtual memory)

  4. fork Function • Fig. 8.1 (proc/fork1.c) • write()is notbuffered • Standard I/O library is buffered • standard output is line buffered if it’s connected to a terminal device (program runs interactively) • otherwise, it’s fully buffered

  5. exit Function • Normal termination • Return from main() • Call exit() • Call _exit() or _Exit() • Return of the last thread from its start routine • Call pthread_exit()from the last thread • Abnormal termination • Call abort() – generate SIGABRT to itself • Receive a signal (generated by the kernel or some other process) • Response of the last thread to a cancellation request

  6. exit Function • Normal termination - exit status in exit() [converted into termination status by kernel when _exit() called] • Abnormal termination – kernel generates a termination status indicating the reason • Parent process obtain termination status via wait() or waitpid()

  7. exit Function

  8. Zombie (defunct) Process • What happen parent terminates before child? • initinherits child and becomes its parent • When child terminates before parent? • If child completely disappeared, parent wouldn’t be able to fetch its termination status when and if parent was finally ready to check if child had terminated • Kernel keeps a small amount of information (process ID, termination status, and amount of CPU time used) in the process tablefor every terminating process, so the information is available when parent of the terminating process calls wait()or waitpid() • Process that has terminated, but whose parent has not yet waited for it, is called a zombie

  9. wait and waitpid Functions • When process terminates, either normally or abnormally, kernel notifies the parent by sending it SIGCHLD signal (to be ignored or handled) • Process that calls wait or waitpidcan • Block, if all of its children are still running • Return immediately with the termination status of a child, if a child has terminated and is waiting for its termination status to be fetched • Return immediately with an error, if it doesn’t have any child processes • Returns process ID of terminated process

  10. wait and waitpid Functions • With multiple children, wait returns on termination of any process • waitpid waits for a specific process pid_twaitpid(pid_tpid, int *statloc, int options); • pid == -1: wait for any child • Pid > 0: wait for child of pid

More Related