进程标识符

本文介绍了进程中的六个关键ID,包括进程ID、父进程ID、有效用户ID、有效组ID、实际用户ID和实际组ID,并提供了获取这些ID的相关函数示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

每一个进程有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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值