In the web page there is a sentence to describe tty drivers.

registered tty drivers

The /proc/tty/drivers file shows all of the currently registered tty drivers.

Here is some info about w and /proc/tty/drivers.

debian8@hwy:~$ w
 23:53:38 up 2 min,  1 user,  load average: 0.47, 0.46, 0.20
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
debian8  :0       :0               23:51   ?xdm?   4.62s  0.05s /usr/bin/lxsess
debian8@hwy:~$ cat /proc/tty/drivers
/dev/tty             /dev/tty        5       0 system:/dev/tty
/dev/console         /dev/console    5       1 system:console
/dev/ptmx            /dev/ptmx       5       2 system
/dev/vc/0            /dev/vc/0       4       0 system:vtmaster
serial               /dev/ttyS       4 64-95 serial
pty_slave            /dev/pts      136 0-1048575 pty:slave
pty_master           /dev/ptm      128 0-1048575 pty:master
unknown              /dev/tty        4 1-63 console

Which line in the /proc/tty/drivers reflect w command?

  • :0 is Xorg which isn't a tty. That's just the column where a tty would be listed if the user were on one. – Bratchley Jan 11 '17 at 20:20

The w utility reads the utmp database wtmp to display its TTY info, as far as I know. This is written to by xdm, apparently by using something called sessreg (an X11 utility that "manage utmp/wtmp entries for non-init clients").

The sessreg manual says to put a line like

sessreg -a -l $DISPLAY -x /etc/X11/xdm/Xservers $USER

in the X11 Xstartup script. On my OpenBSD machine, the line actually reads (in /etc/X11/xdm/Xstartup)

exec /usr/X11R6/bin/sessreg  -a -w /var/log/wtmp -u /var/run/utmp       -x /etc/X11/xdm/Xservers -l $DISPLAY -h "" $USER

The -l flag has the following description in the sessreg manual:

This describes the "line" name of the entry. For terminal sessions, this is the final pathname segment of the terminal device filename (e.g. ttyd0). For X sessions, it should probably be the local display name given to the users session (e.g. :0). If none is specified, the terminal name will be determined with ttyname(3) and stripped of leading components.

As an experiment:

$ doas sessreg -a -l hello kk

(kk is me, and doas is the OpenBSD "equivalent" of sudo)

$ w
 7:31PM  up 10:55, 2 users, load averages: 1.20, 1.16, 1.10
kk       p0     8:47AM     0 tmux: client (/tmp/tmux-1000/default)
kk       he -                 7:31PM     0 -

$ doas sessreg -d -l hello kk

$ w
 7:32PM  up 10:56, 1 user, load averages: 1.22, 1.17, 1.11
kk       p0     8:47AM     0 tmux: client (/tmp/tmux-1000/default)

$ last | head -n 3
kk        hello                             Wed Jan 11 19:31 - 19:31  (00:00)
kk        ttyC0                             Wed Jan 11 18:54 - 19:21  (00:27)
kk        ttyp0            Wed Jan 11 08:47   still logged in

In conclusion: :0 is just a text string put there by the sessreg utility. It could be anything, but it's most likely the value of $DISPLAY.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.