geteuid():返回有效用户的ID。
getuid():返回实际用户的ID。
有效用户ID(EUID)是你最初执行程序时所用的ID
表示该ID是程序的所有者
真实用户ID(UID)是程序执行过程中采用的ID
该ID表明当前运行位置程序的执行者
举个例子
程序myprogram的所有者为501/anna
以501运行该程序此时UID和EUID都是501
但是由于中间要访问某些系统资源
需要使用root身份
此时UID为0而EUID仍是501
相关函数:getegid, setregid, setgid
头文件:#include <unistd.h> #include <sys/types.h>
定义函数:gid_t getgid(void);
函数说明:getgid()用来取得执行目前进程的组识别码。
返回值:返回组识别码
范例
#include <unistd.h>
#include <sys/types.h>
main()
{
printf("gid is %d\n", getgid());
}
执行:
gid is 0 //当使用root 身份执行范例程序时