Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC declarations: typedef __pid_t pid_t?

Tags:

fork

unix

gcc

I am confused about the declaration of (for example) pid_t. What does __pid_t mean? Is it another type defined elsewhere? If yes, where? Why is my types.h in ubuntu 13.04 64bit defining pid_t like:

#ifndef __pid_t_defined
typedef __pid_t pid_t;
#define __pid_t_defined
#endif

and not something like

typedef int pid_t;

I saw some websites that have types.h headers with the declaration done the last way. This is one: http://www.sde.cs.titech.ac.jp/~gondow/dwarf2-xml/HTML-rxref/app/gcc-3.3.2/lib/gcc-lib/sparc-sun-solaris2.8/3.3.2/include/sys/types.h.html

UPDATE:

Ok I found out that a pid_t is an __pid_t which is an __PID_T_TYPE which is which is an __S32_TYPE which is an int. My question now is why is this? POSIX only states that pid_t has to be a signed integer, so why make the declaration enter soo deep in header files?

like image 903
goncalo luis Avatar asked May 30 '14 12:05

goncalo luis


1 Answers

If you are pulling up your types.h via 'man types' then at the top of the header file(under description in the man page) there should exist an include file that defines '__pid_t' at some point as a signed integer(if Ubuntu claims that their types are POSIX compliant; otherwise pid_t could be anything). The symbol ' __' is considered reserved(C standard, dunno about C++). If I had to take a wild guess as to why pid_t is defined as __pid_t and not some int is because __pid_t is what Debian's or the Linux Kernel's developers decided to use for the process ID variable name in all of their library functions; therefore only '__pid_t' needs to be changed to change the integer size for a process ID.

You should really look around before asking a question, similar stackoverflow questions are easily found: Size of pid_t, uid_t, gid_t on Linux .

like image 149
ballard26 Avatar answered Oct 02 '22 23:10

ballard26