Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Sep 2013 00:34:51 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        doc@freebsd.org
Subject:   Re: Tweaks to the wait(2) manpage
Message-ID:  <20130924213451.GS41229@kib.kiev.ua>
In-Reply-To: <201309241631.44920.jhb@freebsd.org>
References:  <201309121643.46422.jhb@freebsd.org> <20130914081144.GZ41229@kib.kiev.ua> <alpine.BSF.2.00.1309140656570.36819@wonkity.com> <201309241631.44920.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--m0ev5QnFa5X6wbjY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Sep 24, 2013 at 04:31:44PM -0400, John Baldwin wrote:
> On Saturday, September 14, 2013 9:11:48 am Warren Block wrote:
> > On Sat, 14 Sep 2013, Konstantin Belousov wrote:
> >=20
> > > On Thu, Sep 12, 2013 at 04:43:46PM -0400, John Baldwin wrote:
> > >> I have some tweaks to the wait(2) manpage, in particular to the sect=
ions on
> > >> wait6() and idtypes.  I did also change two other places to use uppe=
rcase for
> > >> ID since that seems to be what we do in other pages.  The alternate =
rendered
> > >> text is below followed by the diff.  One structural change I chose t=
o make was
> > >> using a tagged list for the non-standard idtypes.  Our manpages in g=
eneral
> > >> prefer tagged lists to bullet lists for enumerations.  I left the li=
st of
> > >> standard types as-is as it includes a fourth bullet point that would=
 not have
> > >> an associated tag (though one could perhaps move that into the parag=
raph
> > >> introducing the list of standard types if a tagged list was desired)=
=2E  I kept
> > >> reading this page as I was writing this e-mail and changed more bits=
 to
> > >> attempt to be more consisent with existing paragraphs, etc.:
> > >>
> > >>      The broadest interface of all functions in this family is wait6=
() which
> > >>      is otherwise very much like wait4() but with a few very importa=
nt dis-
> > >>      tinctions.  To wait for exited processes the option flag WEXITE=
D must be
> > > I did not liked the introductory sentence above, but was not able to
> > > formulate the idea better.  Specifically, I do not like the narrative=
 tone,
> > > and think that 'broadest' and 'distinction' should be expressed bette=
r.
> >=20
> > Agreed about "broadest", it's hard to tell what that means.  How about:
> >=20
> >    wait6() is the most general function in this family, differing from
> >    wait4() in these important ways:
> >=20
> >    To wait for exited processes, the WEXITED option flag must be
> >    explicitly specified.  This allows waiting for processes which have
> >    experienced other status changes without having to also handle the
> >    exit status from terminated processes.
> >=20
> >    Instead of the traditional rusage argument, the wrusage argument
> >    points to a structure defined as:
>=20
> I've fixed the zero -> NULL case Konstantin pointed out (and another one).
> I also made a stab at fixing this.  I actually changed the prior paragraph
> to state that both wait4 and wait6 are the general functions for this API
> and then went from there.  I also reworded the descriptions of the flags
> in options and clarified that WTRAPPED is implicit the same as WEXITED in
> a few places.
>=20
> At this point it's probably easiest for me to just put the entire page he=
re:
>=20
> WAIT(2)                   FreeBSD System Calls Manual                  WA=
IT(2)
>=20
> NAME
>      wait, waitid, waitpid, wait3, wait4, wait6 -- wait for processes to
>      change status
>=20
> LIBRARY
>      Standard C Library (libc, -lc)
>=20
> SYNOPSIS
>      #include <sys/types.h>
>      #include <sys/wait.h>
>=20
>      pid_t
>      wait(int *status);
>=20
>      pid_t
>      waitpid(pid_t wpid, int *status, int options);
>=20
>      #include <sys/signal.h>
>=20
>      int
>      waitid(idtype_t idtype, id_t id, siginfo_t *info, int options);
>=20
>      #include <sys/time.h>
>      #include <sys/resource.h>
>=20
>      pid_t
>      wait3(int *status, int options, struct rusage *rusage);
>=20
>      pid_t
>      wait4(pid_t wpid, int *status, int options, struct rusage *rusage);
>=20
>      pid_t
>      wait6(idtype_t idtype, id_t id, int *status, int options,
>          struct __wrusage *wrusage, siginfo_t *infop);
>=20
> DESCRIPTION
>      The wait() function suspends execution of its calling thread until s=
tatus
>      information is available for a child process or a signal is received=
=2E  On
>      return from a successful wait() call, the status area contains infor=
ma-
>      tion about the process that reported a status change as defined belo=
w.
>=20
>      The wait() call is the same as wait4() with a wpid value of -1, with=
 an
>      options value of zero, and a rusage value of NULL.
>=20
>      The wait4() and wait6() system calls provide a more general interfac=
e for
>      programs that need to wait for specific child processes, that need
>      resource utilization statistics accumulated by child processes, or t=
hat
>      require options.  The other wait functions are implemented using eit=
her
>      wait4() or wait6().
>=20
>      The wait6() function is the most general function in this family and=
 dif-
>      fers from wait4() in these important ways:
Still, this sentence highlights the difference with wait4(), but there were
no description for wait4() given before.  Might be, modulo the language
rewording, say
	The wait6() function is the most general function in this family and
	its distinctive features are:
>=20
>      All of the desired process statuses to be waited on must be explicit=
ly
>      specified in options.  The wait(), waitpid(), wait3(), and wait4() f=
unc-
>      tions all implicitly wait for exited and trapped processes, but the
>      waitid() and wait6() functions require the corresponding WEXITED and
>      WTRAPPED flags to be explicitly specified.  This allows waiting for =
pro-
>      cesses which have experienced other status changes without having to=
 also
>      handle the exit status from terminated processes.
>=20
>      Instead of the traditional rusage argument, the wrusage arguments po=
ints
>      to a structure defined as:
And there,
	The wait6() function takes the wrusage argument, which points to ...

I like other parts of the text.
>=20
>      struct __wrusage {
>              struct rusage   wru_self;
>              struct rusage   wru_children;
>      };
>=20
>      This allows the calling process to collect resource usage statistics=
 from
>      both its own child process as well as from its grand children.  When=
 no
>      resource usage statistics are needed this pointer can be NULL.
>=20
>      The last argument infop must be either NULL or a pointer to a siginf=
o_t
>      structure.  If non-NULL, the structure is filled with the same data =
as
>      for a SIGCHLD signal delivered when the process changed state.
>=20
>      The set of child processes to be queried is specified by the argumen=
ts
>      idtype and id.  The separate idtype and id arguments support many ot=
her
>      types of identifers in addition to process IDs and process group IDs.
>=20
>            o   If idtype is P_PID, waitid() and wait6() wait for the child
>                process with a process ID equal to (pid_t)id.
>=20
>            o   If idtype is P_PGID, waitid() and wait6() wait for the chi=
ld
>                process with a process group ID equal to (pid_t)id.
>=20
>            o   If idtype is P_ALL, waitid() and wait6() wait for any child
>                process and the id is ignored.
>=20
>            o   If idtype is P_PID or P_PGID and the id is zero, waitid() =
and
>                wait6() wait for any child process in the same process gro=
up as
>                the caller.
>=20
>      Non-standard identifier types supported by this implementation of
>      waitid() and wait6() are:
>=20
>      P_UID     Wait for processes whose effective user ID is equal to (ui=
d_t)
>                id.
>=20
>      P_GID     Wait for processes whose effective group ID is equal to (g=
id_t)
>                id.
>=20
>      P_SID     Wait for processes whose session ID is equal to id.  If the
>                child process started its own session, its session ID will=
 be
>                the same as its process ID.  Otherwise the session ID of a
>                child process will match the caller's session ID.
>=20
>      P_JAILID  Waits for processes within a jail whose jail identifier is
>                equal to id.
>=20
>      For the wait(), wait3(), and wait4() functions, the single wpid argu=
ment
>      specifies the set of child processes for which to wait.
>=20
>            o   If wpid is -1, the call waits for any child process.
>=20
>            o   If wpid is 0, the call waits for any child process in the
>                process group of the caller.
>=20
>            o   If wpid is greater than zero, the call waits for the proce=
ss
>                with process ID wpid.
>=20
>            o   If wpid is less than -1, the call waits for any process wh=
ose
>                process group ID equals the absolute value of wpid.
>=20
>      The status argument is defined below.
>=20
>      The options argument contains the bitwise OR of any of the following
>      options.
>=20
>      WCONTINUED  Report the status of selected processes that have contin=
ued
>                  from a job control stop by receiving a SIGCONT signal.
>=20
>      WNOHANG     Do not block when there are no processes wishing to repo=
rt
>                  status.
>=20
>      WUNTRACED   Report the status of selected processes which are stoppe=
d due
>                  to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal.
>=20
>      WSTOPPED    An alias for WUNTRACED.
>=20
>      WTRAPPED    Report the status of selected processes which are being
>                  traced via ptrace(2) and have trapped or reached a break-
>                  point.  This flag is implicitly set for the functions wa=
it(),
>                  waitpid(), wait3(), and wait4().
>                  For the waitid() and wait6() functions, the flag has to =
be
>                  explicitly included in options if status reports from tr=
apped
>                  processes are expected.
>=20
>      WEXITED     Report the status of selected processes which have termi-
>                  nated.  This flag is implicitly set for the functions wa=
it(),
>                  waitpid(), wait3(), and wait4().
>                  For the waitid() and wait6() functions, the flag has to =
be
>                  explicitly included in options if status reports from te=
rmi-
>                  nated processes are expected.
>=20
>      WNOWAIT     Keep the process whose status is returned in a waitable
>                  state.  The process may be waited for again after this c=
all
>                  completes.
>=20
>      For the waitid() and wait6() functions, at least one of the options
>      WEXITED, WUNTRACED, WSTOPPED, WTRAPPED, or WCONTINUED must be specif=
ied.
>      Otherwise there will be no events for the call to report.  To avoid =
hang-
>      ing indefinitely in such a case these functions return -1 with errno=
 set
>      to EINVAL.
>=20
>      If rusage is non-NULL, a summary of the resources used by the termin=
ated
>      process and all its children is returned.
>=20
>      If wrusage is non-NULL, separate summaries are returned for the reso=
urces
>      used by the terminated process and the resources used by all its chi=
l-
>      dren.
>=20
>      If infop is non-NULL, a siginfo_t structure is returned with the si_=
signo
>      field set to SIGCHLD and the si_pid field set to the process ID of t=
he
>      process reporting status.
>=20
>      When the WNOHANG option is specified and no processes wish to report=
 sta-
>      tus, waitid() sets the si_signo and si_pid fields in infop to zero.
>      Checking these fields is the only way to know if a status change was
>      reported.
>=20
>      When the WNOHANG option is specified and no processes wish to report=
 sta-
>      tus, wait4() and wait6() return a process id of 0.
>=20
>      The waitpid() function is identical to wait4() with an rusage value =
of
>      NULL.  The older wait3() call is the same as wait4() with a wpid val=
ue of
>      -1.  The wait4() function is identical to wait6() with the flags WEX=
ITED
>      and WTRAPPED set in options and infop set to NULL.
>=20
>      The following macros may be used to test the current status of the
>      process.  Exactly one of the following four macros will evaluate to a
>      non-zero (true) value:
>=20
>      WIFCONTINUED(status)
>              True if the process has not terminated, and has continued af=
ter a
>              job control stop.  This macro can be true only if the wait c=
all
>              specified the WCONTINUED option.
>=20
>      WIFEXITED(status)
>              True if the process terminated normally by a call to _exit(2=
) or
>              exit(3).
>=20
>      WIFSIGNALED(status)
>              True if the process terminated due to receipt of a signal.
>=20
>      WIFSTOPPED(status)
>              True if the process has not terminated, but has stopped and =
can
>              be restarted.  This macro can be true only if the wait call =
spec-
>              ified the WUNTRACED option or if the child process is being
>              traced (see ptrace(2)).
>=20
>      Depending on the values of those macros, the following macros produc=
e the
>      remaining status information about the child process:
>=20
>      WEXITSTATUS(status)
>              If WIFEXITED(status) is true, evaluates to the low-order 8 b=
its
>              of the argument passed to _exit(2) or exit(3) by the child.
>=20
>      WTERMSIG(status)
>              If WIFSIGNALED(status) is true, evaluates to the number of t=
he
>              signal that caused the termination of the process.
>=20
>      WCOREDUMP(status)
>              If WIFSIGNALED(status) is true, evaluates as true if the ter=
mina-
>              tion of the process was accompanied by the creation of a core
>              file containing an image of the process when the signal was
>              received.
>=20
>      WSTOPSIG(status)
>              If WIFSTOPPED(status) is true, evaluates to the number of the
>              signal that caused the process to stop.
>=20
> NOTES
>      See sigaction(2) for a list of termination signals.  A status of 0 i=
ndi-
>      cates normal termination.
>=20
>      If a parent process terminates without waiting for all of its child =
pro-
>      cesses to terminate, the remaining child processes are assigned the =
par-
>      ent process 1 ID (the init process ID).
>=20
>      If a signal is caught while any of the wait() calls are pending, the=
 call
>      may be interrupted or restarted when the signal-catching routine ret=
urns,
>      depending on the options in effect for the signal; see discussion of
>      SA_RESTART in sigaction(2).
>=20
>      The implementation queues one SIGCHLD signal for each child process =
whose
>      status has changed; if wait() returns because the status of a child
>      process is available, the pending SIGCHLD signal associated with the
>      process ID of the child process will be discarded.  Any other pending
>      SIGCHLD signals remain pending.
>=20
>      If SIGCHLD is blocked and wait() returns because the status of a chi=
ld
>      process is available, the pending SIGCHLD signal will be cleared unl=
ess
>      another status of the child process is available.
>=20
> RETURN VALUES
>      If wait() returns due to a stopped, continued, or terminated child
>      process, the process ID of the child is returned to the calling proc=
ess.
>      Otherwise, a value of -1 is returned and errno is set to indicate the
>      error.
>=20
>      If wait6(), wait4(), wait3(), or waitpid() returns due to a stopped,=
 con-
>      tinued, or terminated child process, the process ID of the child is
>      returned to the calling process.  If there are no children not previ=
ously
>      awaited, -1 is returned with errno set to ECHILD.  Otherwise, if WNO=
HANG
>      is specified and there are no stopped, continued or exited children,=
 0 is
>      returned.  If an error is detected or a caught signal aborts the cal=
l, a
>      value of -1 is returned and errno is set to indicate the error.
>=20
>      If waitid() returns because one or more processes have a state chang=
e to
>      report, 0 is returned.  If an error is detected, a value of -1 is
>      returned and errno is set to indicate the error.  If WNOHANG is spec=
ified
>      and there are no stopped, continued or exited children, 0 is returne=
d.
>      The si_signo and si_pid fields of infop must be checked against zero=
 to
>      determine if a process reported status.
>=20
> ERRORS
>      The wait() function will fail and return immediately if:
>=20
>      [ECHILD]           The calling process has no existing unwaited-for =
child
>                         processes.
>=20
>      [ECHILD]           No status from the terminated child process is av=
ail-
>                         able because the calling process has asked the sy=
stem
>                         to discard such status by ignoring the signal SIG=
CHLD
>                         or setting the flag SA_NOCLDWAIT for that signal.
>=20
>      [EFAULT]           The status or rusage argument points to an illegal
>                         address.  (May not be detected before exit of a c=
hild
>                         process.)
>=20
>      [EINTR]            The call was interrupted by a caught signal, or t=
he
>                         signal did not have the SA_RESTART flag set.
>=20
>      [EINVAL]           An invalid value was specified for options, or id=
type
>                         and id do not specify a valid set of processes.
>=20
> SEE ALSO
>      _exit(2), ptrace(2), sigaction(2), exit(3), siginfo(3)
>=20
> STANDARDS
>      The wait(), waitpid(), and waitid() functions are defined by POSIX;
>      wait6(), wait4(), and wait3() are not specified by POSIX.  The
>      WCOREDUMP() macro is an extension to the POSIX interface.
>=20
>      The ability to use the WNOWAIT flag with waitpid() is an extension; =
POSIX
>      only permits this flag with waitid().
>=20
>      POSIX requires waitid() to return the full 32 bits passed to _exit(2=
);
>      this implementation only returns 8 bits like in the other calls.
>=20
> HISTORY
>      The wait() function appeared in Version 6 AT&T UNIX.
>=20
> --=20
> John Baldwin

--m0ev5QnFa5X6wbjY
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.21 (FreeBSD)

iQIcBAEBAgAGBQJSQgV6AAoJEJDCuSvBvK1BJQ0P+wc+HZBqNh52RSrhK1igdSt4
XUaedW548aEOWCEB8lkcYmNuy+VxpbO7FqERp+MlPmFdJNLIbO3gjCXtYOR0fTie
THxw2cppLAYAVwS8iYBtsOi2U2XUNi6ew3LImO+GhoDG9TXkMAWtK4NOKLeGaznf
RKDPud4Q3Q0zxTafR9jEyBFk+dPD7qkChPQjXm3RqXiHHBn6OyosRxe3paF8YFGO
cdFHEJESiV445EHkqIm1xiwEL5VEXCcKj3/eBaY+6ma8EMdOS4zul31QEQuEq540
mCzmJ2Mc6iz/4Hea+/zCLPa3OmtbFPPOwdyQKiJuGTgqvfinWoPkCpQ3IhJH3kIV
jVHhCB0yhxnqw7PhBXy3LjwLJMwovyrlJ56S/sW0tg01Tv40ADZsQDhcbwLTdbst
LoeYXBGdhrta/twGjS/EXHU8YNqTRiZCRCG9+LaNt9vUouRhJ+8PrL6tSdNeHvaP
Tnimt4fOKBy8FOe8E8Mpf3aEd6mgYgvcQiIyo9+XVg90v3PE+unJpbgoDztezqoX
xL4krLIl7+hWn78S8pHmpndXT67WNYefw5gTyCBMgZ4yLUgDbr3eq03MdMo8xNkD
1UaAyxghix21axtIpZO/MO1bgHiSgiLWbt0thQ2F/8tMeW6PGpH3YgEqjqcJtVjj
xnr5+vHvMXBLokemU0Ty
=qozs
-----END PGP SIGNATURE-----

--m0ev5QnFa5X6wbjY--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130924213451.GS41229>