【发布时间】:2019-09-28 06:48:40
【问题描述】:
我在 linux 中用 c 编写代码,我必须显示当前正在运行的进程的 pid 以及父进程的 pid。我正在使用 ps -a 命令进行交叉检查,但它没有出现在那里。任何帮助将不胜感激
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
void main()
{
sleep(4);
printf("The process id of the current process running is %d\n",getpid());
sleep(4);
printf("The process id of the parent process is %d\n", getppid());
}
【问题讨论】:
-
你怎么打电话给
ps -a?它应该工作。尝试./program并在另一个控制台中运行pidof ./program -
@DavidRanieri 我正在使用 2 个终端。我在一个终端中执行文件并在另一个终端中运行 ps -a 命令
-
@DavidRanieri 它只显示当前进程的进程ID,而不是父进程的pid
标签: linux system-calls