頭檔案
#include<sys/types.h>
#include<unistd.h>
函式原型
uid_t getuid(void);
說明
uid_t是定義在頭檔案sys/types.h中,它通常是一個小整形。函式返回一個調用程式的真實用戶ID,一般來說,這個函式都是會調用成功的。
注意: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.
範例
#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
uid_t uid;
uid = getuid();
printf("User IDs: uid=%d\n", uid);
Exit(0);
}