Linux 上 pid_t、uid_t、gid_t 的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1922761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Size of pid_t, uid_t, gid_t on Linux
提问by Joe Shaw
On Linux systems (either 32- or 64-bit), what is the size of pid_t
, uid_t
, and gid_t
?
在 Linux 系统(32 位或 64 位)上pid_t
,uid_t
、 和的大小是gid_t
多少?
采纳答案by Dave
#include <stdio.h>
#include <sys/types.h>
int main()
{
printf("pid_t: %zu\n", sizeof(pid_t));
printf("uid_t: %zu\n", sizeof(uid_t));
printf("gid_t: %zu\n", sizeof(gid_t));
}
EDIT:Per popular request (and because, realistically, 99% of the people coming to this question are going to be running x86 or x86_64)...
编辑:每个流行的请求(因为,实际上,99% 的人来这个问题将运行 x86 或 x86_64)...
On an i686 and x86_64 (so, 32-bit and 64-bit) processor running Linux >= 3.0.0, the answer is:
在运行 Linux >= 3.0.0 的 i686 和 x86_64(因此,32 位和 64 位)处理器上,答案是:
pid_t: 4
uid_t: 4
gid_t: 4
回答by Joe Shaw
On intel architectures, sizes are defined in /usr/include/bits/typesizes.h
:
在英特尔架构上,大小定义为/usr/include/bits/typesizes.h
:
#define __UID_T_TYPE __U32_TYPE
#define __GID_T_TYPE __U32_TYPE
#define __PID_T_TYPE __S32_TYPE
In other words, uid_t
and gid_t
are unsigned 32-bit integers and pid_t
is a signed 32-bit integer. This applies for both 32- and 64-bits.
换句话说,uid_t
和gid_t
是无符号 32 位整数并且pid_t
是有符号 32 位整数。这适用于 32 位和 64 位。
I am not sure what they are on other architectures offhand as I don't have any available at the moment, but the definitive way is to compile a program which prints the output of sizeof(uid_t)
, etc.
我不确定它们在其他架构上是什么,因为我目前没有可用的,但最终的方法是编译一个程序,打印输出sizeof(uid_t)
等。