如何获得用户名,从认识的uid在Linux API? [英] How to get username from know uid in linux api?

查看:576
本文介绍了如何获得用户名,从认识的uid在Linux API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的Linux 新。我需要在我的C应用程序知道从给定的用户ID的用户名。是否有任何的Linux API 函数可用来得到这个?

I am new in linux. I need to know user name from given user id in my c application. Is there any linux api function available to get this?

感谢

推荐答案

如果您想从C程序的用户名,然后 getpwuid 可能是最简单的方法。
这里的男人项: http://man7.org/linux/man-pages /man3/getpwnam.3.html

If you want to get the username from a c program then getpwuid is probably the easiest way. Man entry here: http://man7.org/linux/man-pages/man3/getpwnam.3.html

在命令行中,我只想通过passwd中的grep:

From the command line, I would just grep through passwd:

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

这篇关于如何获得用户名,从认识的uid在Linux API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆