man-pages/man2/uname.2.html
2021-03-31 01:06:50 +01:00

262 lines
6.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of UNAME</TITLE>
</HEAD><BODY>
<H1>UNAME</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-10-10<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
uname - get name and information about current kernel
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/utsname.h">sys/utsname.h</A>&gt;</B>
<P>
<B>int uname(struct utsname *</B><I>buf</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>uname</B>()
returns system information in the structure pointed to by
<I>buf</I>.
The
<I>utsname</I>
struct is defined in
<I>&lt;<A HREF="file:///usr/include/sys/utsname.h">sys/utsname.h</A>&gt;</I>:
<P>
struct utsname {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;sysname[];&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Operating&nbsp;system&nbsp;name&nbsp;(e.g.,&nbsp;&quot;Linux&quot;)&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;nodename[];&nbsp;&nbsp;&nbsp;/*&nbsp;Name&nbsp;within&nbsp;&quot;some&nbsp;implementation-defined
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;network&quot;&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;release[];&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Operating&nbsp;system&nbsp;release&nbsp;(e.g.,&nbsp;&quot;2.6.28&quot;)&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;version[];&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Operating&nbsp;system&nbsp;version&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;machine[];&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Hardware&nbsp;identifier&nbsp;*/
#ifdef _GNU_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;domainname[];&nbsp;/*&nbsp;NIS&nbsp;or&nbsp;YP&nbsp;domain&nbsp;name&nbsp;*/
#endif
};
<P>
The length of the arrays in a
<I>struct utsname</I>
is unspecified (see NOTES);
the fields are terminated by a null byte ('\0').
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EFAULT</B>
<DD>
<I>buf</I>
is not valid.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, SVr4.
There is no
<B>uname</B>()
call in 4.3BSD.
<P>
The
<I>domainname</I>
member (the NIS or YP domain name) is a GNU extension.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
This is a system call, and the operating system presumably knows
its name, release and version.
It also knows what hardware it runs on.
So, four of the fields of the struct are meaningful.
On the other hand, the field
<I>nodename</I>
is meaningless:
it gives the name of the present machine in some undefined
network, but typically machines are in more than one network
and have several names.
Moreover, the kernel has no way of knowing
about such things, so it has to be told what to answer here.
The same holds for the additional
<I>domainname</I>
field.
<P>
To this end, Linux uses the system calls
<B><A HREF="/cgi-bin/man/man2html?2+sethostname">sethostname</A></B>(2)
and
<B><A HREF="/cgi-bin/man/man2html?2+setdomainname">setdomainname</A></B>(2).
Note that there is no standard that says that the hostname set by
<B><A HREF="/cgi-bin/man/man2html?2+sethostname">sethostname</A></B>(2)
is the same string as the
<I>nodename</I>
field of the struct returned by
<B>uname</B>()
(indeed, some systems allow a 256-byte hostname and an 8-byte nodename),
but this is true on Linux.
The same holds for
<B><A HREF="/cgi-bin/man/man2html?2+setdomainname">setdomainname</A></B>(2)
and the
<I>domainname</I>
field.
<P>
The length of the fields in the struct varies.
Some operating systems
or libraries use a hardcoded 9 or 33 or 65 or 257.
Other systems use
<B>SYS_NMLN</B>
or
<B>_SYS_NMLN</B>
or
<B>UTSLEN</B>
or
<B>_UTSNAME_LENGTH</B>.
Clearly, it is a bad
idea to use any of these constants; just use sizeof(...).
Often 257 is chosen in order to have room for an internet hostname.
<P>
Part of the utsname information is also accessible via
<I>/proc/sys/kernel/</I>{<I>ostype</I>,
<I>hostname</I>,
<I>osrelease</I>,
<I>version</I>,
<I>domainname</I>}.
<A NAME="lbAI">&nbsp;</A>
<H3>C library/kernel differences</H3>
<P>
Over time, increases in the size of the
<I>utsname</I>
structure have led to three successive versions of
<B>uname</B>():
<I>sys_olduname</I>()
(slot
<I>__NR_oldolduname</I>),
<I>sys_uname</I>()
(slot
<I>__NR_olduname</I>),
and
<I>sys_newuname</I>()
(slot
<I>__NR_uname)</I>.
The first one
used length 9 for all fields;
the second
used 65;
the third also uses 65 but adds the
<I>domainname</I>
field.
The glibc
<B>uname</B>()
wrapper function hides these details from applications,
invoking the most recent version of the system call provided by the kernel.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+uname">uname</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+getdomainname">getdomainname</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+gethostname">gethostname</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+uts_namespaces">uts_namespaces</A></B>(7)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="7"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="8"><A HREF="#lbAH">NOTES</A><DD>
<DL>
<DT id="9"><A HREF="#lbAI">C library/kernel differences</A><DD>
</DL>
<DT id="10"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="11"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:35 GMT, March 31, 2021
</BODY>
</HTML>