Back to index

glibc  2.9
Typedefs | Enumerations | Functions
waitpid.c File Reference
#include <errno.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stddef.h>
#include "siginfo.h"

Go to the source code of this file.

Typedefs

typedef enum __idtype __idtype_t

Enumerations

enum  __idtype { P_PID, P_PGID = 2, P_ALL = 7 }

Functions

__pid_t __getpgid (__pid_t pid)
int __waitid (__idtype_t idtype, __pid_t id, __siginfo_t *infop, int options)
__pid_t __libc_waitpid (__pid_t pid, int *stat_loc, int options)

Typedef Documentation

typedef enum __idtype __idtype_t

Enumeration Type Documentation

enum __idtype
Enumerator:
P_PID 
P_PGID 
P_ALL 

Definition at line 26 of file waitpid.c.

  {
    /* Look for processes based upon a given PID.  */
    P_PID,

    /* Look for processes based upon a given process-group ID.  */
    P_PGID = 2,

    /* Look for any process.  */
    P_ALL = 7,
  } __idtype_t;

Function Documentation

Definition at line 28 of file __getpgid.c.

{
  return __pgrpsys (4, pid);
}
__pid_t __libc_waitpid ( __pid_t  pid,
int stat_loc,
int  options 
)

Definition at line 56 of file waitpid.c.

{
  __idtype_t idtype;
  __pid_t tmp_pid = pid;
  __siginfo_t infop;

  if (pid <= WAIT_MYPGRP)
    {
      if (pid == WAIT_ANY)
       {
         /* Request the status for any child.  */
         idtype = P_ALL;
       }
      else if (pid == WAIT_MYPGRP)
       {
         /* Request the status for any child process that has
            a pgid that's equal to that of our parent.  */
         tmp_pid = __getpgid (0);
         idtype = P_PGID;
       }
      else /* PID < -1 */
       {
         /* Request the status for any child whose pgid is equal
            to the absolute value of PID.  */
         tmp_pid = pid & ~0; /* XXX not pseudo-insn */
         idtype = P_PGID;
       }
    }
  else
    {
      /* Request the status for the child whose pid is PID.  */
      idtype = P_PID;
    }

  if (__waitid (idtype, tmp_pid, &infop, options | WEXITED | WTRAPPED) < 0)
    return -1;

  switch (infop.__code)
    {
    case EXITED:
      *stat_loc = W_EXITCODE (infop.__status, 0);
      break;
    case STOPPED:
    case TRAPPED:
      *stat_loc = W_STOPCODE (infop.__status);
      break;
    case KILLED:
      /* Don't know what to do with continue, since it isn't documented.
        Putting it here seemed the right place though. */
    case CONTINUED:
      *stat_loc = infop.__status;
      /* FALLTHROUGH */
    case CORED:
      *stat_loc |= WCOREFLAG;
      break;
    }

  /* Return the PID out of the INFOP structure instead of the one we were
     called with, to account for cases of being called with -1 to signify
     any PID.  */
  return infop.__pid;
}

Here is the call graph for this function:

int __waitid ( __idtype_t  idtype,
__pid_t  id,
__siginfo_t *  infop,
int  options 
)