OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / uname.2
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 2014-09-21 "Linux" "Linux Programmer's Manual"
28 .SH NAME
29 uname \- get name and information about current kernel
30 .SH SYNOPSIS
31 .B #include <sys/utsname.h>
32 .sp
33 .BI "int uname(struct utsname *" buf );
34 .SH DESCRIPTION
35 .BR uname ()
36 returns system information in the structure pointed to by
37 .IR buf .
38 The
39 .I utsname
40 struct is defined in
41 .IR <sys/utsname.h> :
42 .in +4n
43 .nf
44
45 struct utsname {
46     char sysname[];    /* Operating system name (e.g., "Linux") */
47     char nodename[];   /* Name within "some implementation-defined
48                           network" */
49     char release[];    /* Operating system release (e.g., "2.6.28") */
50     char version[];    /* Operating system version */
51     char machine[];    /* Hardware identifier */
52 #ifdef _GNU_SOURCE
53     char domainname[]; /* NIS or YP domain name */
54 #endif
55 };
56
57 .fi
58 .in
59 The length of the arrays in a
60 .I struct utsname
61 is unspecified (see NOTES);
62 the fields are terminated by a null byte (\(aq\\0\(aq).
63 .SH RETURN VALUE
64 On success, zero is returned.
65 On error, \-1 is returned, and
66 .I errno
67 is set appropriately.
68 .SH ERRORS
69 .TP
70 .B EFAULT
71 .I buf
72 is not valid.
73 .SH CONFORMING TO
74 SVr4, POSIX.1-2001.
75 There is no
76 .BR uname ()
77 call in 4.3BSD.
78 .PP
79 The
80 .I domainname
81 member (the NIS or YP domain name) is a GNU extension.
82 .SH NOTES
83 This is a system call, and the operating system presumably knows
84 its name, release and version.
85 It also knows what hardware it runs on.
86 So, four of the fields of the struct are meaningful.
87 On the other hand, the field
88 .I nodename
89 is meaningless:
90 it gives the name of the present machine in some undefined
91 network, but typically machines are in more than one network
92 and have several names.
93 Moreover, the kernel has no way of knowing
94 about such things, so it has to be told what to answer here.
95 The same holds for the additional
96 .I domainname
97 field.
98 .LP
99 To this end, Linux uses the system calls
100 .BR sethostname (2)
101 and
102 .BR setdomainname (2).
103 Note that there is no standard that says that the hostname set by
104 .BR sethostname (2)
105 is the same string as the
106 .I nodename
107 field of the struct returned by
108 .BR uname ()
109 (indeed, some systems allow a 256-byte hostname and an 8-byte nodename),
110 but this is true on Linux.
111 The same holds for
112 .BR setdomainname (2)
113 and the
114 .I domainname
115 field.
116 .LP
117 The length of the fields in the struct varies.
118 Some operating systems
119 or libraries use a hardcoded 9 or 33 or 65 or 257.
120 Other systems use
121 .B SYS_NMLN
122 or
123 .B _SYS_NMLN
124 or
125 .B UTSLEN
126 or
127 .BR _UTSNAME_LENGTH .
128 Clearly, it is a bad
129 idea to use any of these constants; just use sizeof(...).
130 Often 257 is chosen in order to have room for an internet hostname.
131 .LP
132 Part of the utsname information is also accessible via
133 .IR /proc/sys/kernel/ { ostype ,
134 .IR hostname ,
135 .IR osrelease ,
136 .IR version ,
137 .IR domainname }.
138 .SS C library/kernel ABI differences
139 .LP
140 Over time, increases in the size of the
141 .I utsname
142 structure have led to three successive versions of
143 .BR uname ():
144 .IR sys_olduname ()
145 (slot
146 .IR __NR_oldolduname ),
147 .IR sys_uname ()
148 (slot
149 .IR __NR_olduname ),
150 and
151 .IR sys_newuname ()
152 (slot
153 .IR __NR_uname) .
154 The first one
155 .\" That was back before Linux 1.0
156 used length 9 for all fields;
157 the second
158 .\" That was also back before Linux 1.0
159 used 65;
160 the third also uses 65 but adds the
161 .I domainname
162 field.
163 The glibc
164 .BR uname ()
165 wrapper function hides these details from applications,
166 invoking the most recent version of the system call provided by the kernel.
167 .SH SEE ALSO
168 .BR uname (1),
169 .BR getdomainname (2),
170 .BR gethostname (2),
171 .BR namespaces (7)
172 .SH COLOPHON
173 This page is part of release 3.79 of the Linux
174 .I man-pages
175 project.
176 A description of the project,
177 information about reporting bugs,
178 and the latest version of this page,
179 can be found at
180 \%http://www.kernel.org/doc/man\-pages/.