1、相关函数
#include<unistd.h>
#include<sys/types.h>
pid_t getpid(void); 获得当前进程ID
uid_t getuid(void); 获得当前进程的实际用户ID
uit_t geteuid(void); 获得当前进程的有效用户ID
git_t getgid(void); 获得当前进程的用户组ID
pit_t getppid(void); 获得当前进程的父进程ID
pit_t getpgid(void); 获得当前进程所在的进程组ID
pit_t getpgid(pid_t pid); 获得进程ID为pid的进程所在的进程组ID
2、使用示例
#include<unistd.h>
#include<stdio.h>
int main(void)
{
printf("pid:%d\n",getpid());
printf("ppid:%d\n",getpid());
printf("uid:%d\n",getuid());
printf("euid:%d\n",geteuid());
printf("user gid:%d\n",getgid());
printf("gid:%d\n",getpgrp());
printf("pgid:%d\n",getpgid(getpid()));
printf("ppgid:%d\n",getpgid(getppid()));
return 0;
}
运行结果: