[Previous]
[Contents]
[Next]

uname()

get information about the operating system

Synopsis:

#include <sys/utsname.h>
int uname( struct utsname *name );

Description:

The uname() function stores information about the current operating system in the structure pointed to by the argument name.

The structure utsname is defined in <sys/utsname.h>, and contains at least the following structure members:

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.

Returns:

A nonnegative value. If an error occurs, it returns -1 and sets errno.

Errors:

EINTR
Call interrupted by a signal.

Examples:

/*
 * 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>

void main()
  {
    struct utsname sysinfo;

    if( uname( &sysinfo ) == -1 ) {
       perror( "uname" );
       exit( 1 );
    }
    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 );
    exit( 0 );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno, qnx_osinfo()


[Previous]
[Contents]
[Next]