我正在使用 Linux (3.13.0-24-generic#46-Ubuntu),并编写了一个简单的 C 程序
关于pid
。
编译时,我遇到了一些问题:
gcc pid_test.c
,没问题。gcc -std=c99 pid_test.c
或gcc -std=c11 pid_test.c
,给出错误:
error: unknown type name ‘pid_t’
pid_test.c:
// getpid() & getppid() test
#include <stdio.h>
#include <unistd.h>
int pid_test() {
pid_t pid, ppid;
pid = getpid();
ppid = getppid();
printf("pid: %d, ppid: %d\n", pid, ppid);
return 0;
}
int main(int argc, void *argv[]) {
pid_test();
return 0;
}
我用谷歌搜索过;人们似乎在 Windows 上有类似的问题,但我使用的是 Linux。 c99
或 c11
是否删除 pid_t
或移动到其他 header ?或者……
最佳答案
以下对我有用
// getpid() & getppid() test
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h> //NOTE: Added
int pid_test() {
pid_t pid, ppid;
pid = getpid();
ppid = getppid();
printf("pid: %d, ppid: %d\n", pid, ppid);
return 0;
}
int main(int argc, void *argv[]) {
pid_test();
return 0;
}
我找到了 here
关于c99 - 错误 : unknown type name ‘pid_t’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32282270/