I understand that unix user IDs (UIDs) are usually 16 or 32 bit unsigned integers but how can I find out for any given system (in a shell)?

link|improve this question
feedback

3 Answers

up vote 5 down vote accepted

You'll need to look in <limits.h> (or one of the files it includes, e.g., <sys/syslimits.h> on OS X) for the #define of "UID_MAX".

Most recent operating systems (Solaris 2.x, OS X, BSD, Linux, HP-UX 11i, AIX 6) can handle up to two billion (2^31-2), so I would assume that and make a workaround for the more obscure systems that don't.

link|improve this answer
feedback

That's an interesting question. I'd be surprised if there was a standard, portable method to determine this.

I don't have a Linux box handy, but the "id" command on FreeBSD 8.0 wraps back to zero:

# id 4294967296
uid=0(root) gid=0(wheel) groups=0(wheel),5(operator)

I'm sure this is undefined behavior, but I'd wager that most versions of "id" would either wrap to zero with 65536 (if 16-bit UID) and 4294967296 or error out if you went beyond the system limit.

link|improve this answer
feedback

In this link the question is asked and a responder uses a trial & error method to determine the system in question uses a signed long int, leaving 31 bits to store the value, with a max of 2,147,483,647. You could maybe using a similar method.

# groupadd -g 42949672950 testgrp
# more /etc/group
testgrp:*:2147483647:
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.