Chapter Contents

Previous

Next
getsid

getsid



Get Session Leader ID for a Process

Portability: UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
USAGE NOTES
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <sys/types.h>
#include <unistd.h>
pid_t getsid(pid_t pid);


DESCRIPTION

The getsid function returns the process id for the session leader for a specific process. The argument pid should be either the id of a specific process or 0 to request the id of the session leader for the current process.


RETURN VALUE

getsid returns the session leader's process id, or -1 if it fails.


USAGE NOTES

The getsid 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 getsid()       */
   pid_t sid;                 

/*---------------------------------------*/
/* Get the Session Leader id for the     */
/* Current Process                       */
/*---------------------------------------*/
printf("\nGet the Session Leader 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 session leader id for           */
/* this process                            */
   sid = getsid(pid);   

/* Test for Error */
   if (sid == -1)
   {
      perror("Call to getsid failed");
      exit(EXIT_FAILURE);
   }
   else
   {
printf
 ("       The process id: %d\n", (int)pid);
printf
 ("The Session Leader id: %d\n", (int)sid);
   }
 
/* version 2                               */
/* Reset errno to zero for error handling  */
   errno = 0;            

 /* 0 implies current processs id          */
   pid = 0;             

/* get the session leader id for           */
/* this process                            */
   sid = getsid(pid);   

/* Test for Error */
   if (sid == -1)
   {
      perror("Call to getsid failed");
      exit(EXIT_FAILURE);
   }
   else
   {
 printf("       The process id: %d\n", 
  (int)pid);
 printf("The Session Leader id: %d\n", 
  (int)sid);
   }
 
   exit(EXIT_SUCCESS);

}  /* end of main() */


RELATED FUNCTIONS

setsid


Chapter Contents

Previous

Next

Top of Page

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