( standard c libraries translation )getuid

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版本的改动

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值