getpgrp() — Get the process group ID

Standards

Standards / Extensions C or C++ Dependencies

POSIX.1
XPG4
XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _POSIX_SOURCE
#include <unistd.h>

pid_t getpgrp(void);

General description

Finds the process group ID of the calling process.

Returned value

Returns the found value. It is always successful.

There are no documented errno values.

Example

CELEBG13
⁄* CELEBG13

   This example gets all the process group IDs.
 
 *⁄
#define _POSIX_SOURCE
#include <unistd.h>
#include <sys⁄wait.h>

main() {
  int status;

  if (fork() == 0) {
    if (fork() == 0) {
      printf("grandchild's pid is %d, process group id is %d\n",
             (int) getpid(), (int) getpgrp());
      exit(0);
    }
    printf("child's pid is %d, process group id is %d\n",
           (int) getpid(), (int) getpgrp());
    wait(&status);
    exit(0);
  }
  printf("parent's pid is %d, process group id is %d\n",
         (int) getpid(), (int) getpgrp());
  printf("the parent's parent's pid is %d\n", (int) getppid());
  wait(&status);
}
Output
parent's pid is 5373959, process group id is 5111816
the parent's parent's pid is 5111816
child's pid is 5832710, process group id is 5111816
grandchild's pid is 196617, process group id is 5111816

Related information