[英]Process id of parent process not showing up in ps-a command
我正在 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 command
不會給你命令的PID,你需要grep
:
ps -a | grep command
如果你不想使用grep
你可以使用
pidof command
但是,如果您還想要您需要的 PPID:
ps -ef | grep command
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.