Linux中 pid_t 类型的定义.

说明:涉及到的头文件(.h),目录默认都是基于 /usr/include/ 目录.

1.在 "/sys/types.h"中,有下列内容:

1 #include <bits/types.h>

2 #ifndef __pid_t_defined

3 100 typedef __pid_t pid_t;

4 101 # define __pid_t_defined

5 102 #endif

很明显, pid_t 只是 __pid_t 的别名.或者说, pid_t 类型其实是 __pid_t 类型.

2.在"bits/types.h"中,有下列内容:

1 /* We want __extension__ before typedef's that use nonstandard base types

2 118    such as `long long' in C89 mode.  */

3 119 # define __STD_TYPE             __extension__ typedef

4 120 #elif __WORDSIZE == 64

5 ...

6 #include <bits/typesizes.h>     /* Defines __*_T_TYPE macros.  */

7 __STD_TYPE __PID_T_TYPE __pid_t;        /* Type of process identifications.

8  */

由第一行和第二行的注释中,我们可以忽略 __extension__ 的分析.故 __STD_TYPE 表示 typedef.所以在第七行的代码中,可以知道:

__pid_t 类型 其实是 __PID_T_TYPE 类型.

3.在 "bits/typesizes.h" 中,有以下内容:

1 /* See <bits/types.h> for the meaning of these macros.  This file exists so

2  28    that <bits/types.h> need not vary across different GNU platforms.  */

3 

4 ...

5 #define __PID_T_TYPE            __S32_TYPE

由此我们知道 __PID_T_TYPE 就是 __S32_TYPE 类型.并且这个文件没有引用任何其他的头文件.

4.在 "bits/types.h" 文件中,我们看到有以下内容:

1 #define __S32_TYPE              int

由此,最终可以知道,__S32_TYPE 就是 int 类型,也就是说, pid_t  其实就是 int 类型.

引自:  http://doudouclever.blog.163.com/blog/static/17511231020112248130302/

你可能感兴趣的:(linux)