from small one page howto to huge articles all in one place

search text in:




Other .linuxhowtos.org sites:gentoo.linuxhowtos.org



Last additions:
using iotop to find disk usage hogs

using iotop to find disk usage hogs

words:

887

views:

209807

userrating:


May 25th. 2007:
Words

486

Views

258802

why adblockers are bad


Workaround and fixes for the current Core Dump Handling vulnerability affected kernels

Workaround and fixes for the current Core Dump Handling vulnerability affected kernels

words:

161

views:

150129

userrating:


April, 26th. 2006:

Druckversion
You are here: manpages





ttyslot

Section: C Library Functions (3)
Updated: 202-0-08
Index Return to Main Contents
 

NAME

ttyslot - find the slot of the current user's terminal in some file  

LIBRARY

Standard C library (libc,~-lc)  

SYNOPSIS

#include <unistd.h>       /* See NOTES */
int ttyslot(void);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)): ttyslot():
    Since glibc 2.24:
        _DEFAULT_SOURCE
    From glibc 2.20 to glibc 2.23:
        _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
    glibc 2.19 and earlier:
        _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
 

DESCRIPTION

The legacy function ttyslot() 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.  

Ancient 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 [aq]0[aq] or [aq]1[aq], where [aq]0[aq] meant "ignore". The second character denoted the terminal: [aq]8[aq] stood for "/dev/tty8". The third character was an argument to getty(8) indicating the sequence of line speeds to try ([aq]-[aq] was: start trying 110 baud). Thus a typical line was "18-". A hang on some line was solved by changing the [aq]1[aq] to a [aq]0[aq], signaling init, changing back again, and signaling init again. 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 ([aq]0[aq] was: cycle through 30-120-15-110 baud; [aq]4[aq] was for the o-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 -like systems have /etc/inittab instead.  

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 -like systems do not, and hence cannot refer to it. Thus, on such systems the documentation says that ttyslot() returns the current user's index in the user accounting data base.  

RETURN VALUE

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 BS-like systems, but -1 on System -like systems.  

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7).
InterfaceAttributeValue
ttyslot() Thread safetyM-Unsafe
 

VERSIONS

The utmp file is found in various places on various systems, such as /etc/utmp, /var/adm/utmp, /var/run/utmp.  

STANDARDS

None.  

HISTORY

SUSv1; marked as LEGACY in SUSv2; removed in POSIX.-2001. SUSv2 requires -1 on error. The glibc2 implementation of this function reads the file _PATH_TTYS, defined in <ttyent.h> as "/etc/ttys". It returns 0 on error. Since Linux systems do not usually have "/etc/ttys", it will always return 0. On BS-like systems and Linux, the declaration of ttyslot() is provided by <unistd.h>. On System -like systems, the declaration is provided by <stdlib.h>. Since glibc 2.24, <stdlib.h> also provides the declaration with the following feature test macro definitions: (_XOPEN_SOURCE >= 500 ||
        (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
    && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) Minix also has fttyslot(fd).  

SEE ALSO

getttyent(3), ttyname(3), utmp(5)


 

Index

NAME
LIBRARY
SYNOPSIS
DESCRIPTION
Ancient history
Ancient history (2)
The semantics of ttyslot
RETURN VALUE
ATTRIBUTES
VERSIONS
STANDARDS
HISTORY
SEE ALSO





Support us on Content Nation
rdf newsfeed | rss newsfeed | Atom newsfeed
- Powered by LeopardCMS - Running on Gentoo -
Copyright 2004-2025 Sascha Nitsch Unternehmensberatung GmbH
Valid XHTML1.1 : Valid CSS
- Level Triple-A Conformance to Web Content Accessibility Guidelines 1.0 -
- Copyright and legal notices -
Time to create this page: 16.1 ms