Usage of the getpwuid Function

Source: Internet
Author: User

Getpwuid
Define the function: struct passwd * getpwuid (uid_t UID );
Function Description: getpwuid () is used to search for the user identification code specified by the UID parameter one by one. When it is found, the user's data is returned in a structure. For details about the structure, refer to the passwd structure for the user data.
. For the passwd structure, see getpwent ().
The Return Value Returns the passwd structure data. If the return value is null, it indicates that no data exists or there is an error.
Error.

 

The passwd structure related to system data is defined as follows:

Struct passwd

{

Char * pw_name;/* User name */

Char * pw_passwd;/* password .*/

_ Uid_t pw_uid;/* User ID .*/

_ Gid_t pw_gid;/* Group ID .*/

Char * pw_gecos;/* real name */

Char * pw_dir;/* main directory .*/

Char * pw_shell;/* shell used */

};

 

Instance:

# Include <PWD. h>
# Include <sys/types. h>
Main ()
{
Struct passwd * user;
User = getpwuid (6 );
Printf ("Name: % s \ n", user-> pw_name );
Printf ("uid: % d \ n", user-> pw_uid );
Printf ("Home: % s \ n", user-> pw_dir );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.