AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 105260
Accepted
Josef
Josef
Asked: 2010-01-22 18:28:20 +0800 CST2010-01-22 18:28:20 +0800 CST 2010-01-22 18:28:20 +0800 CST

Unix UID 有多大(以位为单位)?

  • 772

我知道 unix 用户 ID (UID) 通常是 16 位或 32 位无符号整数,但我如何才能找到任何给定系统(在 shell 中)?

linux unix uid
  • 4 4 个回答
  • 30597 Views

4 个回答

  • Voted
  1. Best Answer
    DM.
    2010-01-22T19:04:29+08:002010-01-22T19:04:29+08:00

    您需要查看<limits.h>(或其中包含的文件之一,例如sys/syslimits.h在 OS X 上)#define的UID_MAX.

    最新的操作系统(Solaris 2.x、OS X、BSD、Linux、HP-UX 11i、AIX 6)可以处理多达 20 亿2^31-2(不。

    • 14
  2. kirelagin
    2014-03-31T01:10:52+08:002014-03-31T01:10:52+08:00

    glibc 为所有这些系统类型提供了定义。

    您可以检查/usr/include/bits/typesizes.h:

    % grep UID_T /usr/include/bits/typesizes.h
    #define __UID_T_TYPE            __U32_TYPE
    

    接下来你看看/usr/include/bits/types.h:

    % grep '#define __U32_TYPE' /usr/include/bits/types.h
    #define __U32_TYPE              unsigned int
    

    这可以让您找出 C 类型。由于您需要以字节为单位的大小,因此最好的选择是根据以下规范解析 typedef 名称types.h:

    We define __S<SIZE>_TYPE and __U<SIZE>_TYPE for the signed and unsigned
    variants of each of the following integer types on this machine.
    
     16      -- "natural" 16-bit type (always short)
     32      -- "natural" 32-bit type (always int)
     64      -- "natural" 64-bit type (long or long long)
     LONG32      -- 32-bit type, traditionally long
     QUAD        -- 64-bit type, always long long
     WORD        -- natural type of __WORDSIZE bits (int or long)
     LONGWORD    -- type of __WORDSIZE bits, traditionally long
    

    所以,这里有一个单行:

    % grep '#define __UID_T_TYPE' /usr/include/bits/typesizes.h | cut -f 3 | sed -r 's/__([US])([^_]*)_.*/\1 \2/'
    U 32
    

    这里的U意思是unsigned(这也可以是Sfor signed)并且32是大小(在上面的列表中查找它;我认为,大多数时候你可以假设它已经是字节大小,但是如果你希望你的脚本是完全可移植的case开启这个值可能会更好)。

    • 6
  3. Donald Byrd
    2010-01-22T18:54:37+08:002010-01-22T18:54:37+08:00

    在此链接中提出问题,响应者使用试错法确定相关系统使用有符号长整数,留下 31 位来存储值,最大值为 2,147,483,647。

    # groupadd -g 42949672950 testgrp
    # more /etc/group
    testgrp:*:2147483647:
    
    • 4
  4. Geoff Fritz
    2010-01-22T19:04:21+08:002010-01-22T19:04:21+08:00

    这是一个有趣的问题。如果有一种标准的、可移植的方法来确定这一点,我会感到惊讶。

    我手边没有 Linux 机器,但idFreeBSD 8.0 上的命令回零:

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

    我确定这是未定义的行为,但我敢打赌,大多数版本id要么使用65'536(如果是 16 位 UID)包装为零,要么4'294'967'296在超出系统限制时出错。

    • 3

相关问题

  • 你最喜欢的 Linux 发行版是什么?[关闭]

  • 更改 PHP 的默认配置设置?

  • 保护新的 Ubuntu 服务器 [关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve