Chapter Contents

Previous

Next
tcgetpgrp

tcgetpgrp



Get Foreground Process Group Identification

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <unistd.h>

int tcgetpgrp(int fileDescriptor);


DESCRIPTION

tcgetpgrp returns the process group identification (PGID) for the foreground process group associated with a controlling terminal that is referred to by the file descriptor fileDescriptor .

The tcgetpgrp function can be called from a background process to obtain the PGID of a foreground process group. The process can then change from the background group to the foreground process group by making a call to tcsetpgrp , specifying the PGID of the new foreground group as one of the arguments passed to tcsetpgrp .


RETURN VALUE

If successful, tcgetpgrp returns the value of the forground process group identification (PGID). A -1 is returned if unsuccessful.


EXAMPLE

The following example illustrates the use of tcgetpgrp to obtain the PGIDs for stdin , stdout , and stderr :

#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

main()
{
   pid_t stdin_PGID, stdout_PGID, stderr_PGID;

      /* Get the PGIDs for stdin, stdout, and stderr.  */
   stdin_PGID = tcgetpgrp(STDIN_FILENO);
   if (stdin_PGID == -1) {
      printf("Could not get PGID for stdin.n");
      return(EXIT_FAILURE);
   }
   stdout_PGID = tcgetpgrp(STDOUT_FILENO);
   if (stdout_PGID == -1) {
      printf("Could not get PGID for stdout.n");
      return(EXIT_FAILURE);
   }
   stderr_PGID = tcgetpgrp(STDERR_FILENO);
   if (stderr_PGID == -1) {
      printf("Could not get PGID for stderr.n");
      return(EXIT_FAILURE);
   }

   printf("The PGID for stdin is %d.n", stdin_PGID);
   printf("The PGID for stdout is %d.n", stdout_PGID);
   printf("The PGID for stderr is %d.n", stderr_PGID);

   return(EXIT_SUCCESS);
}

Note:    Also see the setpgid example.  [cautionend]


RELATED FUNCTIONS

getpgrp , tcsetpgrp


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.