pid_t pid;
//定义一个进程号类型的变量 pid
The type definition of the process number is often used when creating a process: pid_t. We all know that this type definition is actually an int type. But how is this definition defined in the header file of c under linux? Today I will post the previous process of finding this definition:
1. First, there are the following definitions in /usr/include/sys/types.h
#include <bits/types.h>
#ifndef __pid_t_defined
typedef __pid_t pid_t;
#define __pid_t_defined
#endif
You can see that pid_t is actually of type __pid_t.
2. You can see this definition in /usr/include/bits/types.h
#include <bits/typesizes.h>
#if __WORDSIZE == 32
......
define __STD_TYPE __extension__ typedef
#elif __WORDSIZE == 64
......
#endif
......
__STD_TYPE __PID_T_TYPE __pid_t; /* Type of process identifications. */
It can be seen that __pid_t is defined as extension typedef __PID_T_TYPE.
3. You can see this definition in the file /usr/include/bits/typesizes.h (this file does not contain any header files):
#define __PID_T_TYPE __S32_TYPE
It can be seen that __PID_T_TYPE is defined as __S32_TYPE.
4. In the file /usr/include/bits/types.h we finally found this definition:
#define __S32_TYPE int
From this we finally found the true definition of pid_t: in fact it is of type int.