tcgetpgrp() — Get the foreground process group ID
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <unistd.h>
pid_t tcgetpgrp(int fildes);
General description
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.
Returned value
If successful, tcgetpgrp() returns of the foreground process group's PGID.
If unsuccessful,
tcgetpgrp() returns -1 and sets errno to one of the following values:
- Error Code
- Description
- EBADF
- fildes is not a valid open file descriptor.
- ENOTTY
- The calling process does not have a controlling terminal, or the file is not the controlling terminal.
Example
CELEBT07
/* 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);
}
Output
the foreground process group id of stdout is 4063240
Related information
- unistd.h
- setpgid() — Set process group ID for job control
- setsid() — Create session, set process group ID
- tcdrain() — Wait until output has been transmitted
- tcflow() — Suspend or resume data flow on a terminal
- tcflush() — Flush input or output on a terminal
- tcgetattr() — Get the attributes for a terminal
- tcsendbreak() — Send a break condition to a terminal
- tcsetattr() — Set the attributes for a terminal
- tcsetpgrp() — Set the foreground process group ID