readv2: Note preadv2(..., RWF_NOWAIT) bug in BUGS section
[man-pages.git] / man2 / uname.2
blob295eff29450c026585bf4d7e242d43fc8cbc8101
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" 2007-07-05 mtk: Added details on underlying system call interfaces
26 .\"
27 .TH UNAME 2 2021-03-22 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 uname \- get name and information about current kernel
30 .SH SYNOPSIS
31 .nf
32 .B #include <sys/utsname.h>
33 .PP
34 .BI "int uname(struct utsname *" buf );
35 .fi
36 .SH DESCRIPTION
37 .BR uname ()
38 returns system information in the structure pointed to by
39 .IR buf .
40 The
41 .I utsname
42 struct is defined in
43 .IR <sys/utsname.h> :
44 .PP
45 .in +4n
46 .EX
47 struct utsname {
48     char sysname[];    /* Operating system name (e.g., "Linux") */
49     char nodename[];   /* Name within "some implementation\-defined
50                           network" */
51     char release[];    /* Operating system release
52                           (e.g., "2.6.28") */
53     char version[];    /* Operating system version */
54     char machine[];    /* Hardware identifier */
55 #ifdef _GNU_SOURCE
56     char domainname[]; /* NIS or YP domain name */
57 #endif
59 .EE
60 .in
61 .PP
62 The length of the arrays in a
63 .I struct utsname
64 is unspecified (see NOTES);
65 the fields are terminated by a null byte (\(aq\e0\(aq).
66 .SH RETURN VALUE
67 On success, zero is returned.
68 On error, \-1 is returned, and
69 .I errno
70 is set to indicate the error.
71 .SH ERRORS
72 .TP
73 .B EFAULT
74 .I buf
75 is not valid.
76 .SH CONFORMING TO
77 POSIX.1-2001, POSIX.1-2008, SVr4.
78 There is no
79 .BR uname ()
80 call in 4.3BSD.
81 .PP
82 The
83 .I domainname
84 member (the NIS or YP domain name) is a GNU extension.
85 .SH NOTES
86 This is a system call, and the operating system presumably knows
87 its name, release, and version.
88 It also knows what hardware it runs on.
89 So, four of the fields of the struct are meaningful.
90 On the other hand, the field
91 .I nodename
92 is meaningless:
93 it gives the name of the present machine in some undefined
94 network, but typically machines are in more than one network
95 and have several names.
96 Moreover, the kernel has no way of knowing
97 about such things, so it has to be told what to answer here.
98 The same holds for the additional
99 .I domainname
100 field.
102 To this end, Linux uses the system calls
103 .BR sethostname (2)
105 .BR setdomainname (2).
106 Note that there is no standard that says that the hostname set by
107 .BR sethostname (2)
108 is the same string as the
109 .I nodename
110 field of the struct returned by
111 .BR uname ()
112 (indeed, some systems allow a 256-byte hostname and an 8-byte nodename),
113 but this is true on Linux.
114 The same holds for
115 .BR setdomainname (2)
116 and the
117 .I domainname
118 field.
120 The length of the fields in the struct varies.
121 Some operating systems
122 or libraries use a hardcoded 9 or 33 or 65 or 257.
123 Other systems use
124 .B SYS_NMLN
126 .B _SYS_NMLN
128 .B UTSLEN
130 .BR _UTSNAME_LENGTH .
131 Clearly, it is a bad
132 idea to use any of these constants; just use sizeof(...).
133 Often 257 is chosen in order to have room for an internet hostname.
135 Part of the utsname information is also accessible via
136 .IR /proc/sys/kernel/ { ostype ,
137 .IR hostname ,
138 .IR osrelease ,
139 .IR version ,
140 .IR domainname }.
141 .SS C library/kernel differences
142 Over time, increases in the size of the
143 .I utsname
144 structure have led to three successive versions of
145 .BR uname ():
146 .IR sys_olduname ()
147 (slot
148 .IR __NR_oldolduname ),
149 .IR sys_uname ()
150 (slot
151 .IR __NR_olduname ),
153 .IR sys_newuname ()
154 (slot
155 .IR __NR_uname) .
156 The first one
157 .\" That was back before Linux 1.0
158 used length 9 for all fields;
159 the second
160 .\" That was also back before Linux 1.0
161 used 65;
162 the third also uses 65 but adds the
163 .I domainname
164 field.
165 The glibc
166 .BR uname ()
167 wrapper function hides these details from applications,
168 invoking the most recent version of the system call provided by the kernel.
169 .SH SEE ALSO
170 .BR uname (1),
171 .BR getdomainname (2),
172 .BR gethostname (2),
173 .BR uts_namespaces (7)