May I ask a question about process programming?

Source: Internet
Author: User
I would like to ask a question about process programming-Linux general technology-Linux programming and kernel information. The following is a detailed description. The GNU/Linux programming guide version 2nd contains a sample subroutine in Process Control. The source code getname. c is as follows:

# Include
# Include
# Include
# Include
# Include

Int main (void)
{
Char * login;
Struct passwd * pentry;

/* Get the login name */
If (login = getlogin () = NULL) {/* oops */
Perror ("getlogin ");
Exit (EXIT_FAILURE );
}

/* Get the password entry for login */
If (pentry = getpwnam (login) = NULL ){
Perror ("getpwnam ");
Exit (EXIT_FAILURE );
}

/* Display the password entry */
Printf ("user name: % s \ n", pentry-> pw_name );
Printf ("UID: % d \ n", pentry-> pw_uid );
Printf ("GID: % d \ n", pentry-> pw_gid );
Printf ("gecos: % s \ n", pentry-> pw_gecos );
Printf ("home dir: % s \ n", pentry-> pw_dir );
Printf ("shell: % s \ n", pentry-> pw_shell );

Exit (EXIT_SUCCESS );
}

This program shows which user is running the process and the output user name, UID, and other information. However, a problem occurs during running. After the getlogin () function is called, the returned result is NULL and the user name is not obtained (I log on to the linux system as a common user)
$./Getname
Getlogin: no such file or directory
What is going on?
Related Article

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.