|  Chapter Contents |  Previous |  Next | 
| getpgid | 
| Portability: | UNIX compatible | 
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| USAGE NOTES | |
| EXAMPLE | |
| RELATED FUNCTIONS | 
| SYNOPSIS | 
#include <sys/types.h> #include <unistd.h> pid_t getpgid(pid_t pid);
| DESCRIPTION | 
The getpgid
function returns the process group id for a specific
process id. The argument pid should be the
id of the process, or 0 to request the process
group id for the current process.
| RETURN VALUE | 
getpgid returns the process
group id, or -1 if it fails.
| USAGE NOTES | 
The getpgid function can
only be used with MVS 5.2.2 or a later release.
| EXAMPLE | 
This example is compiled using sascc370 -Krent -o.
 
/*------------------------------------+
| POSIX/UNIX header files             |
+-------------------------------------*/
#include 
#include 
/*------------------------------------+
| ISO/ANSI header files               |
+-------------------------------------*/
#include 
#include 
#include 
/*------------------------------------+
| Name:      main                     |
| Returns:   exit(EXIT_SUCCESS) or 
| exit(EXIT_FAILURE)                  |
+-------------------------------------*
int main()
{
/* current process id from getpid()     */
   pid_t pid;  
               
/* process group id from getpgid()      */
   pid_t pgid;                
/*------------------------------------------*/
/* Get the group process id of the current  */
/* process                                  */
/* Note: Both version 1 and version 2 are   */
/*       equivalent to calling the          */
/*.      getpgrp() function                 */
/*------------------------------------------*/
printf
  ("\nGet the Group Process ID of the 
    Current Process\n");
/* version 1                                 */
/* Set errno to zero for error handling      */
   errno = 0;            
/* get the process id for this process       */
   pid = getpid();       
/* get the group process id for this process  */
   pgid = getpgid(pid); 
/* Test for Error */
   if (pgid == -1)
   {
      perror("Call to getpgid failed");
      exit(EXIT_FAILURE);
   }
   else
   {
      printf
("      The process id: %d\n", (int)pid);
      printf("The process group id:%d\n", 
        (int)pgid);
   }
 
/* version 2                                 */
/* Reset errno to zero for error handling    */
   errno = 0;            
/* 0 implies current processs id             */
   pid = 0;              
/* get the group process id for this process  */
   pgid = getpgid(pid); 
/* Test for Error */
   if (pgid == -1)
   {
      perror("Call to getpgid failed");
      exit(EXIT_FAILURE);
   }
   else
   {
 printf
  ("The process group id: %d\n", (int)pgid);
   }
   exit(EXIT_SUCCESS);
}  /* end of main() */
| RELATED FUNCTIONS | 
getpgrp, setpgid
|  Chapter Contents |  Previous |  Next |  Top of Page | 
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.