我的程序在Linux中找到了pid。但它总是返回0.这应该是这样吗?我用了gcc
。有效吗?我什么时候才能获得没有0的进程ID?这是我的代码。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
int main()
{
pid_t pid;
/* get the process id */
if ((pid = getpid()) < 0)
perror(" unable to get pid");
else
printf(" The process id is %d", pid);
return (0);
}
因此在编译程序后,它总是在终端中打印“进程ID为:0”。