[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