每一个进程有6个重要的id,分别是进程ID,父进程ID,有效用户ID,有效组ID,实际用户ID和实际组ID。
相关函数:
#include <unistd.io>
pid_t getpid(); //返回进程ID
pid_t getppid(); //返回父进程ID
pid_t getuid(); //返回用户ID
pid_t geteuid(); //返回有效用户ID
pid_t getgid(); //返回组ID
pid_t getegid(); //返回有效组ID
eg:
#include <stdio.h>
#include <stdlib.h>
int main()
{
pid_t pid,ppid,uid,euid,gid,egid;
pid=getpid();
ppid=getppid();
uid=getuid;
euid=geteuid();
gid=getgid();
egid=getegid();
printf("id of the current process: %u",pid);//pid_t实际是无符号整型
printf("parent id of the current process: %u",ppid);
printf("user id of the current process: %u",uid);
printf("effective user id of the current process: %u",euid);
printf("group id of the current process: %u",gid);
printf("effective group id of the current process: %u",egid);
return 0;
}