linux - 如何从linux api中已知的uid获取用户名?

标签 linux bash api gcc

我是 linux 的新用户。我需要从我的 C 应用程序中给定的用户 ID 中了解用户名。有吗linux api函数可以得到这个吗?

谢谢

最佳答案

如果您想从 C 程序获取用户名,那么 getpwuid 可能是最简单的方法。 此处输入:http://man7.org/linux/man-pages/man3/getpwnam.3.html

从命令行,我只需 grep 通过 passwd:

grep 1000 /etc/passwd | cut -f1 -d:

关于linux - 如何从linux api中已知的uid获取用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21816560/

相关文章:

bash - 使用 bash 连接到 HIVE

android - 使用GSON存储在Android中解析的Json

android - 获取多个艺术家的专辑

linux - 使用 sed 命令格式化输出

c - 将已删除的文件重新附加到目录

linux - 用于进入多个目录并执行命令的命令行 bash

bash - 在 sed 中的变量后面附加文本

regex - 如何检查 bash 中字符串的最后一个字符?

ios - 通过对象数组过滤 API 请求响应?

python - 如何在 Linux 上重命名进程?