qfedu-linux-advanced-level/day2/test_pid.c

22 lines
471 B
C
Raw Normal View History

2023-08-15 19:05:13 +08:00
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// 进程号,父进程号,组进程号
pid_t pid, ppid, pgid;
pid = getpid(); // 获取当前进程的进程号
ppid = getppid(); // 获取当前进程的父进程号
// pgid = __getpgid(0); // 获取当前进程所属的组进程号
pgid = getpgid(ppid);
printf("pid = %d\nppid = %d\npgid = %d\n", pid, ppid, pgid);
while (1)
;
return 0;
}