Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <unistd.h>
pid_t tcgetpgrp(int fildes);
Gets the process group ID (PGID) of the foreground process group associated with the terminal referred to by fildes. tcgetpgrp() can run from a background process, but the information may subsequently be changed by a process in the foreground process group.
If successful, tcgetpgrp() returns of the foreground process group's PGID.
⁄* CELEBT07
This example gets the foreground PGID.
*⁄
#define _POSIX_SOURCE
#include <termios.h>
#include <unistd.h>
#include <sys⁄wait.h> ⁄*FIX: was #include <sys⁄wait.h> *⁄
#include <stdio.h>
main() {
pid_t pid;
if ((pid = tcgetpgrp(STDOUT_FILENO)) < 0)
perror("tcgetpgrp() error");
else
printf("the foreground process group id of stdout is %d\n",
(int) pid);
}
the foreground process group id of stdout is 4063240