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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:36:58  来源:igfitidea点击:

Size of pid_t, uid_t, gid_t on Linux

clinux64-bit32-bitsizeof

提问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_tuid_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_tand gid_tare unsigned 32-bit integers and pid_tis a signed 32-bit integer. This applies for both 32- and 64-bits.

换句话说,uid_tgid_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)等。

回答by Steve Emmerson

The standarddefines pid_tas a "signed integer type" and uid_tand gid_tmerely as "integer types" (so portable code shouldn't assume any particular type for them).

标准定义pid_t为“有符号整数类型”,uid_t并且gid_t仅定义为“整数类型”(因此可移植代码不应为它们假定任何特定类型)。