Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c99 - error: unknown type name ‘pid_t’

Tags:

c

pid

c99

c11

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…

like image 220
user218867 Avatar asked Aug 29 '15 02:08

user218867


1 Answers

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

like image 63
Guru Prasad Avatar answered Oct 16 '22 06:10

Guru Prasad