Section: Linux Programmer's Manual (3)
Return to Main Contents
ttyslot - find the slot of the current user's terminal in some file
/* on BSD-like systems, and Linux */
/* on System V-like systems */
Feature Test Macro Requirements for glibc (see
_XOPEN_SOURCE && _XOPEN_SOURCE_ < 500 && _XOPEN_SOURCE_EXTENDED
The legacy function
returns the index of the current user's entry in some file.
Now "What file?" you ask.
Well, let's first look at some history.
There used to be a file
in UNIX V6, that was read by the
program to find out what to do with each terminal line.
Each line consisted of three characters.
The first character was either '0' or '1',
where '0' meant "ignore".
The second character denoted the terminal: '8' stood for "/dev/tty8".
The third character was an argument to
indicating the sequence of line speeds to try ('-' was: start trying
Thus a typical line was "18-".
A hang on some line was solved by changing the '1' to a '0',
signaling init, changing back again, and signaling init again.
In UNIX V7 the format was changed: here the second character
was the argument to
indicating the sequence of line speeds to try ('0' was: cycle through
300-1200-150-110 baud; '4' 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 systems have
Ancient history (2)
On the other hand, there is the file
listing the people currently logged in.
It is maintained by
It has a fixed size, and the appropriate index in the file was
call to find the number of the line in
(counting from 1).
The semantics of ttyslot
Thus, the function
returns the index of the controlling terminal of the calling process
in the file
and that is (usually) the same as the index of the entry for the
current user in the file
BSD still has the
file, but System V-like systems do not, and hence cannot refer to it.
Thus, on such systems the documentation says that
returns the current user'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.
Multithreading (see pthreads(7))
function calls thread-unsafe function
so it is not thread-safe.
SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
SUSv2 requires -1 on error.
The utmp file is found various places on various systems, such as
The glibc2 implementation of this function reads the file
It returns 0 on error.
Since Linux systems do not usually have "/etc/ttys", it will
always return 0.
Minix also has
This page is part of release 3.74 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
- Ancient history
- Ancient history (2)
- The semantics of ttyslot
- RETURN VALUE
- Multithreading (see pthreads(7))
- CONFORMING TO
- SEE ALSO