Estratto del documento

Wait and waitpid Functions

The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

Name

Wait, waitpid - wait for a child process to stop or terminate

Synopsis

#include <sys/types.h>
#include <sys/wait.h>
pid_t wait(int *stat_loc);
pid_t waitpid(pid_t pid, int *stat_loc, int options);

Description

The wait() and waitpid() functions allow the calling process to obtain status information pertaining to one of its child processes. Various options permit status information to be obtained for child processes that have terminated or stopped. If status information is available for two or more child processes, the order in which their status is reported is unspecified.

The wait() function will suspend execution of the calling thread until status information for one of its terminated child processes is available, or until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. If more than one thread is suspended in wait() or waitpid() awaiting termination of the same process, exactly one thread will return the process status at the time of the target process termination. If status information is available prior to the call to wait(), return will be immediate.

The waitpid() function will behave identically to wait(), if the pid argument is (pid_t)-1 and the options argument is 0. Otherwise, its behaviour will be modified by the values of the pid and options arguments.

The pid argument specifies a set of child processes for which status is requested. The waitpid() function will only return the status of a child process from this set:

  • If pid is equal to (pid_t)-1, status is requested for any child process. In this respect, waitpid() is then equivalent to wait().
  • If pid is greater than 0, it specifies the process ID of a single child process for which status is requested.
  • If pid is 0, status is requested for any child process whose process group ID is equal to that of the calling process.
  • If pid is less than (pid_t)-1, status is requested for any child process whose process group ID is equal to the absolute value of pid.

The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags, defined in the header <sys/wait.h>.

  • WCONTINUED: The waitpid() function will report the status of any continued child process specified by pid whose status has not been reported since it continued from a job control stop.
  • WNOHANG: The waitpid() function will not suspend execution of the calling thread if status is not immediately available.
Anteprima
Vedrai una selezione di 1 pagina su 4
Sistemi operativi - Syscall wait Pag. 1
1 su 4
D/illustrazione/soddisfatti o rimborsati
Acquista con carta o PayPal
Scarica i documenti tutte le volte che vuoi
Dettagli
SSD
Scienze matematiche e informatiche INF/01 Informatica

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher N. A. di informazioni apprese con la frequenza delle lezioni di Sistemi operativi e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Università degli studi di Napoli Federico II o del prof Cotroneo Domenico.
Appunti correlati Invia appunti e guadagna

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community