getuid, geteuid - get user identity
getuid, geteuid - 获取用户id
所需头文件
#include <unistd.h>
#include <sys/types.h>
uid_t getuid(void);
uid_t geteuid(void);
getuid() returns the real user ID of the calling process.
geteuid() returns the effective user ID of the calling process.
getuid函数返回调用函数的真实的用户id
geteuid函数返回调用函数的有效用户id
These functions are always successful.
这些函数永远会调用成功
In UNIX V6 the getuid() call returned (euid << 8) + uid. UNIX V7 introduced separate calls getuid() and geteuid().
在UNIX V6上getuid返回(euid<<8)+uid,UNIX V7就单独的介绍了getuid和geteuid两个调用
The original Linux getuid() and geteuid() system calls supported only 16-bit user IDs. Subsequently, Linux 2.4 added getuid32() and geteuid32(), supporting 32-bit IDs. The glibc getuid() and geteuid() wrapper functions transparently deal with the variations across kernel versions.
原始的getuid和geteuid系统调用仅仅支持16字节的用户id,后来linux2.4增加了getuid32和geteuid32来支持32字节的ID,glibc的getuid和geteuid包裹函数透明的跟随了kernel版本的改动
getgid, getegid - get group identity
所需头文件
#include <unistd.h>
#include <sys/types.h>
gid_t getgid(void);
gid_t getegid(void);
getgid() returns the real group ID of the calling process.
getegid() returns the effective group ID of the calling process.
getgid函数返回调用函数的真实的组id
getegid函数返回调用函数的有效组id
These functions are always successful.
这些函数永远会调用成功
The original Linux getgid() and getegid() system calls supported only 16-bit group IDs. Subsequently, Linux 2.4 added getgid32() and getegid32(), supporting 32-bit IDs. The glibc getgid() and getegid() wrapper functions transparently deal with the variations across kernel versions.
原始的linux getgid和getegid系统调用仅仅支持16字节的组id,后来linux2.4增加了getgid32和getegid32来支持32字节的ID,glibc的getid和geteugid包裹函数透明的跟随了kernel版本的改动
运行结果如下:
getuid, geteuid - 获取用户id
所需头文件
#include <unistd.h>
#include <sys/types.h>
uid_t getuid(void);
uid_t geteuid(void);
getuid() returns the real user ID of the calling process.
geteuid() returns the effective user ID of the calling process.
getuid函数返回调用函数的真实的用户id
geteuid函数返回调用函数的有效用户id
These functions are always successful.
这些函数永远会调用成功
In UNIX V6 the getuid() call returned (euid << 8) + uid. UNIX V7 introduced separate calls getuid() and geteuid().
在UNIX V6上getuid返回(euid<<8)+uid,UNIX V7就单独的介绍了getuid和geteuid两个调用
The original Linux getuid() and geteuid() system calls supported only 16-bit user IDs. Subsequently, Linux 2.4 added getuid32() and geteuid32(), supporting 32-bit IDs. The glibc getuid() and geteuid() wrapper functions transparently deal with the variations across kernel versions.
原始的getuid和geteuid系统调用仅仅支持16字节的用户id,后来linux2.4增加了getuid32和geteuid32来支持32字节的ID,glibc的getuid和geteuid包裹函数透明的跟随了kernel版本的改动
getgid, getegid - get group identity
所需头文件
#include <unistd.h>
#include <sys/types.h>
gid_t getgid(void);
gid_t getegid(void);
getgid() returns the real group ID of the calling process.
getegid() returns the effective group ID of the calling process.
getgid函数返回调用函数的真实的组id
getegid函数返回调用函数的有效组id
These functions are always successful.
这些函数永远会调用成功
The original Linux getgid() and getegid() system calls supported only 16-bit group IDs. Subsequently, Linux 2.4 added getgid32() and getegid32(), supporting 32-bit IDs. The glibc getgid() and getegid() wrapper functions transparently deal with the variations across kernel versions.
原始的linux getgid和getegid系统调用仅仅支持16字节的组id,后来linux2.4增加了getgid32和getegid32来支持32字节的ID,glibc的getid和geteugid包裹函数透明的跟随了kernel版本的改动
testcase如下:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
uid_t uid;
gid_t gid;
uid = getuid();
printf("uid = %d\n", uid);
uid = geteuid();
printf("uid = %d\n", uid);
gid = getgid();
printf("gid = %d\n", gid);
gid = getegid();
printf("gid = %d\n", gid);
return 0;
}
运行结果如下:
cheny.le@cheny-ThinkPad-T420:~/cheny/testCode$ ./a.out
uid = 1001
uid = 1001
gid = 1001
gid = 1001