1UNAME(2)                   Linux Programmer's Manual                  UNAME(2)
2
3
4

NAME

6       uname - get name and information about current kernel
7

SYNOPSIS

9       #include <sys/utsname.h>
10
11       int uname(struct utsname *buf);
12

DESCRIPTION

14       uname()  returns system information in the structure pointed to by buf.
15       The utsname struct is defined in <sys/utsname.h>:
16
17           struct utsname {
18               char sysname[];    /* Operating system name (e.g., "Linux") */
19               char nodename[];   /* Name within "some implementation-defined
20                                     network" */
21               char release[];    /* Operating system release (e.g., "2.6.28") */
22               char version[];    /* Operating system version */
23               char machine[];    /* Hardware identifier */
24           #ifdef _GNU_SOURCE
25               char domainname[]; /* NIS or YP domain name */
26           #endif
27           };
28
29       The length of the arrays  in  a  struct  utsname  is  unspecified  (see
30       NOTES); the fields are terminated by a null byte ('\0').
31

RETURN VALUE

33       On  success,  zero is returned.  On error, -1 is returned, and errno is
34       set appropriately.
35

ERRORS

37       EFAULT buf is not valid.
38

CONFORMING TO

40       POSIX.1-2001, POSIX.1-2008, SVr4.  There is no uname() call in 4.3BSD.
41
42       The domainname member (the NIS or YP domain name) is a GNU extension.
43

NOTES

45       This is a system call, and the operating system  presumably  knows  its
46       name,  release  and  version.   It also knows what hardware it runs on.
47       So, four of the fields of the struct  are  meaningful.   On  the  other
48       hand,  the  field  nodename  is  meaningless:  it gives the name of the
49       present machine in some undefined network, but typically  machines  are
50       in  more than one network and have several names.  Moreover, the kernel
51       has no way of knowing about such things, so it has to be told  what  to
52       answer here.  The same holds for the additional domainname field.
53
54       To  this end, Linux uses the system calls sethostname(2) and setdomain‐
55       name(2).  Note that there is no standard that says  that  the  hostname
56       set  by  sethostname(2) is the same string as the nodename field of the
57       struct returned by uname() (indeed, some systems allow a 256-byte host‐
58       name  and  an  8-byte  nodename),  but this is true on Linux.  The same
59       holds for setdomainname(2) and the domainname field.
60
61       The length of the fields in the struct varies.  Some operating  systems
62       or  libraries  use a hardcoded 9 or 33 or 65 or 257.  Other systems use
63       SYS_NMLN or _SYS_NMLN or UTSLEN or _UTSNAME_LENGTH.  Clearly, it  is  a
64       bad  idea  to  use any of these constants; just use sizeof(...).  Often
65       257 is chosen in order to have room for an internet hostname.
66
67       Part of the utsname information is also accessible  via  /proc/sys/ker‐
68       nel/{ostype, hostname, osrelease, version, domainname}.
69
70   C library/kernel differences
71       Over  time,  increases in the size of the utsname structure have led to
72       three   successive   versions   of   uname():   sys_olduname()    (slot
73       __NR_oldolduname), sys_uname() (slot __NR_olduname), and sys_newuname()
74       (slot __NR_uname).  The first one used length 9  for  all  fields;  the
75       second  used  65; the third also uses 65 but adds the domainname field.
76       The glibc uname() wrapper function hides these  details  from  applica‐
77       tions,  invoking the most recent version of the system call provided by
78       the kernel.
79

SEE ALSO

81       uname(1), getdomainname(2), gethostname(2), namespaces(7)
82

COLOPHON

84       This page is part of release 5.02 of the Linux  man-pages  project.   A
85       description  of  the project, information about reporting bugs, and the
86       latest    version    of    this    page,    can     be     found     at
87       https://www.kernel.org/doc/man-pages/.
88
89
90
91Linux                             2019-03-06                          UNAME(2)
Impressum