On Linux systems (either 32- or 64-bit), what is the size of pid_t
, uid_t
, and gid_t
?
views:
394answers:
3
+4
A:
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.
Joe Shaw
2009-12-17 16:02:44
+15
A:
#include <stdio.h>
#include <sys/types.h>
int main()
{
printf("pid_t: %d\n", sizeof(pid_t));
printf("uid_t: %d\n", sizeof(uid_t));
printf("gid_t: %d\n", sizeof(gid_t));
}
Dave
2009-12-17 16:21:04
Well, the code is portable even if the answers aren't. ;-)
Steve Emmerson
2009-12-19 03:14:20
+2
A:
The standard defines those types as "unsigned integer types", so portable code shouldn't assume any particular type.
Steve Emmerson
2009-12-19 03:15:31