I am using Linux (3.13.0-24-generic #46-Ubuntu), and wrote a simple C program
about pid
.
When compile, I got some issue:
gcc pid_test.c
, this is fine.gcc -std=c99 pid_test.c
or gcc -std=c11 pid_test.c
, gives error: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;
}
I did search with Google; people seem have similar issue on Windows, but I am using Linux. Does c99
or c11
remove pid_t
or move to other header? Or…
The following works for me
// 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;
}
I found it here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With