Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • K kernel
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 13
    • Issues 13
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • erlends-os
  • kernel
  • kernel
  • Wiki
    • Abi
  • waitpid

Last edited by Erlend Sveen Oct 17, 2019
Page history

waitpid

Wait for a child process to change state.

Syntax

#include <sys/wait.h>

pid_t waitpid (pid_t pid, int *status, int options);

Parameters

  • pid

    The process to check on. If this argument is negative, any state change from any child process will be returned. The return value will always be the PID of the process that changed state.

  • status

    A pointer to an integer that will receive the status code and flags. Use the macros below to extract useful information.

  • options

    Options for waitpid:

    • WNOHANG: Do not let waitpid block, and return immediately if no state change has occured.

    • WUNTRACED: Ignored, but definition available for compatibility.

Return Value

The return value is the PID of the process that changed state if successful. Otherwise, the return value is negative and errno is set:

  • ECHILD

    No such child process.

    The process specified is not a child of this process.

  • EINTR

    Interrupted system call. May happen if a signal was delivered to a process waiting with waitpid.

Remarks

Use the following macros to read the value of status:

  • WIFEXITED(status): True if the process terminated normally.
  • WEXITSTATUS(x): Get the return code of the process.
  • WIFSIGNALED(status): State change due to signal delivery.
  • WTERMSIG(status): Terminated due to a signal.
  • WIFSTOPPED(status): Stopped.
Clone repository
  • abi
    • bind
    • chdir
    • close
    • closedir
    • dup2
    • exit
    • fstat
    • getcwd
    • getpgrp
    • getpid
    • gettimeofday
    • ioctl_fcntl
    • kill
    • link
    • lseek
View All Pages