How to get username from know uid in linux api? [d

2019-09-18 00:59发布

问题:

This question already has an answer here:

  • How to retrieve the user name from the user ID 2 answers

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?

Thanks

回答1:

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

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

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


标签: linux bash api gcc