Section (3) ttyslot
ttyslot — find the slot of the current user_zsingle_quotesz_s terminal in some file
#include <unistd.h> /See NOTES */
The legacy function
ttyslot() returns the index of the current
user_zsingle_quotesz_s entry in some file.
Now What file? you ask. Well, let_zsingle_quotesz_s first look at some history.
There used to be a file
/etc/ttys in UNIX V6, that was read by
the init(1) program to find out
what to do with each terminal line. Each line consisted of
three characters. The first character was either _zsingle_quotesz_0_zsingle_quotesz_ or
_zsingle_quotesz_1_zsingle_quotesz_, where _zsingle_quotesz_0_zsingle_quotesz_ meant ignore. The second character denoted
the terminal: _zsingle_quotesz_8_zsingle_quotesz_ stood for /dev/tty8. The third
character was an argument to getty(8) indicating the
sequence of line speeds to try (_zsingle_quotesz_−_zsingle_quotesz_ was: start trying
110 baud). Thus a typical line was 18−. A hang on
some line was solved by changing the _zsingle_quotesz_1_zsingle_quotesz_ to a _zsingle_quotesz_0_zsingle_quotesz_,
signaling init, changing back again, and signaling init
In UNIX V7 the format was changed: here the second character was the argument to getty(8) indicating the sequence of line speeds to try (_zsingle_quotesz_0_zsingle_quotesz_ was: cycle through 300-1200-150-110 baud; _zsingle_quotesz_4_zsingle_quotesz_ was for the on-line console DECwriter) while the rest of the line contained the name of the tty. Thus a typical line was 14console.
Later systems have more elaborate syntax. System V-like
Ancient history (2)
On the other hand, there is the file
/etc/utmp listing the people currently
logged in. It is maintained by login(1). It has a fixed
size, and the appropriate index in the file was determined
by login(1) using the
ttyslot() call to find the
number of the line in
/etc/ttys (counting from 1).
The semantics of ttyslot
Thus, the function
ttyslot() returns the index of the
controlling terminal of the calling process in the file
/etc/ttys, and that is
(usually) the same as the index of the entry for the
current user in the file
/etc/utmp. BSD still has the
/etc/ttys file, but System V-like systems
do not, and hence cannot refer to it. Thus, on such systems
the documentation says that
ttyslot() returns the current user_zsingle_quotesz_s
index in the user accounting data base.
If successful, this function returns the slot number. On error (e.g., if none of the file descriptors 0, 1 or 2 is associated with a terminal that occurs in this data base) it returns 0 on UNIX V6 and V7 and BSD-like systems, but −1 on System V-like systems.
For an explanation of the terms used in this section, see attributes(7).
SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001. SUSv2 requires −1 on error.
The utmp file is found in various places on various
systems, such as
The glibc2 implementation of this function reads the file
_PATH_TTYS, defined in
as /etc/ttys. It returns 0 on error. Since Linux systems do
not usually have /etc/ttys, it will always return 0.
On BSD-like systems and Linux, the declaration of
ttyslot() is provided by
On System V-like systems, the declaration is provided by
Since glibc 2.24,
also provides the declaration with the following feature test
(_XOPEN_SOURCE >= 500 || (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED)) && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
Minix also has
This page is part of release 5.04 of the Linux
man-pages project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
Copyright (C) 2002 Andries Brouwer <aebcwi.nl>
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Since the Linux kernel and libraries are constantly changing, this
manual page may be incorrect or out-of-date. The author(s) assume no
responsibility for errors or omissions, or for damages resulting from
the use of the information contained herein. The author(s) may not
have taken the same level of care in the production of this manual,
which is licensed free of charge, as they might when working
Formatted or processed versions of this manual, if unaccompanied by
the source, must acknowledge the copyright and authors of this work.
This replaces an earlier man page written by Walter Harms