gtpc2m3qC/C++ Language Support User's Guide

geteuid-Get the Effective User ID

This function gets the effective user ID (UID) of the calling function's process.

Format

#include <unistd.h>
uid_t geteuid(void);

Normal Return

The geteuid function returns the effective user ID of the calling process. It is always successful.

Error Return

Not applicable.

Programming Considerations

None.

Examples

The following example provides information for the effective user ID of the caller:

#include <unistd.h>
#include <pwd.h>
#include <stdio.h>
 
int main(void) {
 
char prthdr[] =
             "getpwuid() returned the following info for your user id:"
struct passwd *p;
uid_t uid;
 
if ( ( p = getpwuid ( uid = geteuid() ) ) == NULL )
     perror ( "getpwuid() error" );
  else {
       printf( "%s\n", prthdr );
       printf( "  pw_name  :  %s\n", p->pw_name );
       printf( "  pw_uid   :  %d\n", p->pw_uid  );
       printf( "  pw_gid   :  %d\n", p->pw_gid  );
       printf( "  pw_dir   :  %s\n", p->pw_dir  );
       printf( "  pw_shell :  %s\n", p->pw_shell);
       }
return 0;
}

The geteuid function returns the following information for the user ID of the calling function:

getpwuid() returned the following info for your user id:
pwname   :  TPFUSER1
pw_uid   :  260
pw_gid   :  100
pw_dir   :
pw_shell :

Related Information