![]() |
![]() |
![]() |
![]() |
Get information about the operating system
#include <sys/utsname.h> int uname( struct utsname * name );
libc
The uname() function stores information about the current operating system in the structure pointed to by the argument name.
The system name structure, utsname, is defined in <sys/utsname.h>, and contains at least the following structure members:
Member | Description |
---|---|
char* sysname | Name of the OS. |
char* nodename | Name (number) of this node. |
char* release | Current release level. |
char* version | Current version level. |
char* machine | Hardware type. |
Each of these items is a null-terminated character array.
/* * The following program prints some information about the * system it's running on. */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/utsname.h> int main( void ) { struct utsname sysinfo; if( uname( &sysinfo ) == -1 ) { perror( "uname" ); return EXIT_FAILURE; } printf( "system name : %s\n", sysinfo.sysname ); printf( "node name : %s\n", sysinfo.nodename ); printf( "release name : %s\n", sysinfo.release ); printf( "version name : %s\n", sysinfo.version ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
uname in the Utilities Reference
![]() |
![]() |
![]() |
![]() |