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