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
22                                     (e.g., "2.6.28") */
23               char version[];    /* Operating system version */
24               char machine[];    /* Hardware identifier */
25           #ifdef _GNU_SOURCE
26               char domainname[]; /* NIS or YP domain name */
27           #endif
28           };
29
30       The length of the arrays  in  a  struct  utsname  is  unspecified  (see
31       NOTES); the fields are terminated by a null byte ('\0').
32

RETURN VALUE

34       On  success,  zero is returned.  On error, -1 is returned, and errno is
35       set to indicate the error.
36

ERRORS

38       EFAULT buf is not valid.
39

CONFORMING TO

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

NOTES

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

SEE ALSO

82       uname(1), getdomainname(2), gethostname(2), uts_namespaces(7)
83

COLOPHON

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