Size of pid_t, uid_t, gid_t on Linux

僤鯓⒐⒋嵵緔 提交于 2019-12-28 03:45:30

问题


On Linux systems (either 32- or 64-bit), what is the size of pid_t, uid_t, and gid_t?


回答1:


#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)...

On an i686 and x86_64 (so, 32-bit and 64-bit) processor running Linux >= 3.0.0, the answer is:

pid_t: 4
uid_t: 4
gid_t: 4



回答2:


On intel architectures, sizes are defined in /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.

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.




回答3:


The standard defines pid_t as a "signed integer type" and uid_t and gid_t merely as "integer types" (so portable code shouldn't assume any particular type for them).



来源:https://stackoverflow.com/questions/1922761/size-of-pid-t-uid-t-gid-t-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!