OSDN Git Service

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