Debian Codegraph @

upstream/debian-unstable/man2/uname.2

raw
1 .\" Copyright 2001, Andries E. Brouwer <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH uname 2 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 uname \- get name and information about current kernel
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ,\~ \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/utsname.h>
15 .P
16 .BI "int uname(struct utsname *" buf );
17 .fi
18 .SH DESCRIPTION
19 .BR uname ()
20 returns system information in the structure pointed to by
21 .IR buf .
22 The
23 .I utsname
24 struct is defined in
25 .IR <sys/utsname.h> :
26 .P
27 .in +4n
28 .EX
29 struct utsname {
30 char sysname[]; /* Operating system name (e.g., "Linux") */
31 char nodename[]; /* Name within communications network
32 to which the node is attached, if any */
33 char release[]; /* Operating system release
34 (e.g., "2.6.28") */
35 char version[]; /* Operating system version */
36 char machine[]; /* Hardware type identifier */
37 #ifdef _GNU_SOURCE
38 char domainname[]; /* NIS or YP domain name */
39 #endif
40 };
41 .EE
42 .in
43 .P
44 The length of the arrays in a
45 .I struct utsname
46 is unspecified (see VERSIONS and HISTORY);
47 the fields are terminated by a null byte (\[aq]\[rs]0\[aq]).
48 .SH RETURN VALUE
49 On success, zero is returned.
50 On error, \-1 is returned, and
51 .I errno
52 is set to indicate the error.
53 .SH ERRORS
54 .TP
55 .B EFAULT
56 .I buf
57 is not valid.
58 .SH VERSIONS
59 The
60 .I domainname
61 member (the NIS or YP domain name) is a GNU extension.
62 .P
63 The length of the fields in the struct varies.
64 Some operating systems
65 or libraries use a hardcoded 9 or 33 or 65 or 257.
66 Other systems use
67 .B SYS_NMLN
68 or
69 .B _SYS_NMLN
70 or
71 .B UTSLEN
72 or
73 .BR _UTSNAME_LENGTH .
74 Clearly,
75 it is a bad idea
76 to use any of these constants;
77 just use sizeof(...).
78 SVr4 uses 257, "to support Internet hostnames"
79 \[em]this is the largest value likely to be encountered in the wild\[em].
80 .SH STANDARDS
81 POSIX.1-2024.
82 .SH HISTORY
83 POSIX.1-2001, SVr4, 4.4BSD.
84 .SS C library/kernel differences
85 Over time, increases in the size of the
86 .I utsname
87 structure have led to three successive versions of
88 .BR uname ():
89 .IR sys_olduname ()
90 (slot
91 .IR __NR_oldolduname ),
92 .IR sys_uname ()
93 (slot
94 .IR __NR_olduname ),
95 and
96 .IR sys_newuname ()
97 (slot
98 .IR __NR_uname) .
99 The first one
100 .\" That was back before Linux 1.0
101 used length 9 for all fields;
102 the second
103 .\" That was also back before Linux 1.0
104 used 65;
105 the third also uses 65 but adds the
106 .I domainname
107 field.
108 The glibc
109 .BR uname ()
110 wrapper function hides these details from applications,
111 invoking the most recent version of the system call provided by the kernel.
112 .SH NOTES
113 The kernel has the name, release, version, and supported machine type built in.
114 Conversely, the
115 .I nodename
116 field is configured by the administrator to match the network
117 (this is what the BSD historically calls the "hostname",
118 and is set via
119 .BR sethostname (2)).
120 Similarly, the
121 .I domainname
122 field is set via
123 .BR setdomainname (2).
124 .P
125 Part of the utsname information is also accessible via
126 .IR /proc/sys/kernel/ { ostype ,
127 .IR hostname ,
128 .IR osrelease ,
129 .IR version ,
130 .IR domainname }.
131 .SH SEE ALSO
132 .BR uname (1),
133 .BR getdomainname (2),
134 .BR gethostname (2),
135 .BR uts_namespaces (7)