The detailed description of Linux struct utsname structure is utsname function usage instructions

Source: Internet
Author: User
[Uname System Call]

Function Description:
Obtain the current kernel name and other information.
Usage:
# Include <sys/utsname. h>
Extern int uname (struct utsname * _ name) _ Throw;

Parameters:
_ Name: indicates the buffer zone for storing system information. The prototype is as follows:
Struct utsname
{Char sysname [_ utsname_sysname_length]; // the current operating system name.
Char nodename [_ utsname_nodename_length]; // Network Name
Char release [_ utsname_release_length]; // current release level
Char version [_ utsname_version_length]; // the current version.
Char Machine [_ utsname_machine_length]; // current hardware system type
# If _ utsname_domain_length-0
/* Name of the domain of this node on the network .*/
# Ifdef _ use_gnu
Char domainname [_ utsname_domain_length]; // the current domain name
# Else
Char _ domainname [_ utsname_domain_length];
# Endif
# Endif
};
Return description:
0 is returned when execution is successful. -1 is returned for failure, and errno is set to efault, indicating that the Buf is invalid.
You can use "Man uname" to view the specific usage of uname.
Example:
# Include <sys/utsname. h>
# Include <stdio. h>
# Include <stdlib. h>

Int main ()
{
Struct utsname testbuff;
Int Fb = 0;

Fb = uname (& testbuff );
If (FB <0)
{
Perror ("uname ");
Return 0;
} Else
{
Printf ("sysname: % s/n nodename: % s/n release: % s/n version: % s/n machine: % s/n ",/
Testbuff. sysname ,/
Testbuff. nodename ,/
Testbuff. Release ,/
Testbuff. Version ,/
Testbuff. Machine );
# If _ utsname_domain_length-0
# Ifdef _ use_gnu
Printf ("domainame: % s/n", testbuff. domainname );
// Char domainname [_ utsname_domain_length]; // the current domain name
# Else
Printf ("_ domainame: % s/n", testbuff. _ domainname );
// Char _ domainname [_ utsname_domain_length];
# Endif
# Endif

}
Return 0;
}
This article is from 51cto. com technical blog

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.