landlock_restrict_self.2: tfix
[man-pages.git] / man2 / uname.2
blob0c620b6064aaf50d8134c2f7fe79c570dd9a80ef
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 2021-03-22 "Linux" "Linux Programmer's Manual"
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 .PP
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 .PP
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
42 .EE
43 .in
44 .PP
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 STANDARDS
60 POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD.
61 .PP
62 The
63 .I domainname
64 member (the NIS or YP domain name) is a GNU extension.
65 .SH NOTES
66 The kernel has the name, release, version, and supported machine type built in.
67 Conversely, the
68 .I nodename
69 field is configured by the administrator to match the network
70 (this is what the BSD historically calls the "hostname",
71 and is set via
72 .BR sethostname (2)).
73 Similarly, the
74 .I domainname
75 field is set via
76 .BR setdomainname (2).
77 .PP
78 The length of the fields in the struct varies.
79 Some operating systems
80 or libraries use a hardcoded 9 or 33 or 65 or 257.
81 Other systems use
82 .B SYS_NMLN
84 .B _SYS_NMLN
86 .B UTSLEN
88 .BR _UTSNAME_LENGTH .
89 Clearly, it is a bad
90 idea to use any of these constants; just use sizeof(...).
91 SVr4 uses 257, "to support Internet hostnames"
92 \(em this is the largest value likely to be encountered in the wild.
93 .PP
94 Part of the utsname information is also accessible via
95 .IR /proc/sys/kernel/ { ostype ,
96 .IR hostname ,
97 .IR osrelease ,
98 .IR version ,
99 .IR domainname }.
100 .SS C library/kernel differences
101 Over time, increases in the size of the
102 .I utsname
103 structure have led to three successive versions of
104 .BR uname ():
105 .IR sys_olduname ()
106 (slot
107 .IR __NR_oldolduname ),
108 .IR sys_uname ()
109 (slot
110 .IR __NR_olduname ),
112 .IR sys_newuname ()
113 (slot
114 .IR __NR_uname) .
115 The first one
116 .\" That was back before Linux 1.0
117 used length 9 for all fields;
118 the second
119 .\" That was also back before Linux 1.0
120 used 65;
121 the third also uses 65 but adds the
122 .I domainname
123 field.
124 The glibc
125 .BR uname ()
126 wrapper function hides these details from applications,
127 invoking the most recent version of the system call provided by the kernel.
128 .SH SEE ALSO
129 .BR uname (1),
130 .BR getdomainname (2),
131 .BR gethostname (2),
132 .BR uts_namespaces (7)