码迷,mamicode.com
首页 > 系统相关 > 详细

Linux中 pid_t 类型的定义.

时间:2014-09-02 00:09:53      阅读:356      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   for   文件   

说明:涉及到的头文件(.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中 pid_t 类型的定义.

标签:style   blog   http   color   os   io   ar   for   文件   

原文地址:http://www.cnblogs.com/listened/p/3950537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!