If I open terminal and execute w command then it will show:

user   tty7     :0               12:04   39:56  36.87s  0.06s /sbin/upstart -

Now if open terminator or xterm and execute w command then it will show it's entry in the output of w command like

user   tty7     :0               12:04   39:56  36.87s  0.06s 
/sbin/upstart -
user   pts/2    :0.0             12:50    1.00s  0.02s  0.00s w

but it will not show a new entry when I open gnome-terminal or xfce4-terminal. Why it is showing new session for terminator and not for xfce4-terminal?

  • Are those terminals running your shell as an interactive login shell or just like an interactive shell (see if $- contains an l in the shell). – Kusalananda May 4 '18 at 7:28
  • what is $- . I am getting error himBH command not found and for echo $- it says himBH – Prvt_Yadav May 4 '18 at 7:51
  • I read it earlier but didn't get it. – Prvt_Yadav May 4 '18 at 8:16
  • 1
    Interesting question that attracted two excellent answers. I've edited the title so that others may find this more easily. – Anthony Geoghegan Jul 6 '18 at 10:17

w displays the information stored in utmp (/var/run/utmp typically on Linux systems). This generally is only updated by “login” sessions, i.e. login (for logins on virtual consoles or serial connections), the display manager (for graphical sessions), the SSH server (for SSH connections), and some (most?) terminal emulators. In the latter case, whether or not they update utmp depends on their built-in support and configuration; for example xterm has the ut flag for this (-ut disables utmp updates, +ut enables them), and GNOME Terminal no longer updates utmp directly at all.

So you’re seeing the entries which have been added to utmp in your case: one added by your display manager (on tty7), and others added by some of the terminal emulators you’re using.

It should be possible to wrap commands to add utmp logging to anything you like, using for example libutempter, but that is apparently not as straightforward as one might hope.

  • Is it possible to change the configuration of gnome-terminal – Prvt_Yadav May 4 '18 at 13:39

w does not show terminal sessions. The login database, that the w program reports on, is not a terminal database. (Formally, it is a user accounting database, but the Single Unix Specification is incomplete on this point.)

If it were a terminal database, it would record all of the pseudo terminals that programs use, from the likes of NeoVIM, emacs, tmux, screen, ptybandage, ptyrun, and even script. But it does not, and it is not.

(One can make a similar argument, that needs a slightly greater knowledge of history, about it not recording "call out" terminal usage and the likes of BBS, FidoNet, and UUCP terminal sessions.)

As a login database, it records login sessions, both textual and graphical. The libvte people make the argument that writing to this database is within the purview of the login subsystems, graphical and textual, not within the purview of a terminal emulator that runs within login sessions. This is a fair point, bolstered by the fact that it makes a nonsense of the security of login accounting to allow programs outwith the Trusted Computing Base to write/update the login database.

As such, you shouldn't expect every terminal emulator session to show up as a login session in the login database — or indeed any terminal emulator sessions. Even terminal emulators that are invoking login shells are not doing any actual logging on to the system, and are acting entirely within an already-logged-in session. Terminal emulator writers tried to make the login database record terminal emulator sessions, but the effort has led to a number of problems, long-since recognized.

Conversely, you should expect to see a single record for your GUI login session. (Although, as explained in an article in further reading, in practice this is rather a mess.)

Further reading

  • Thanks for the informative answer. However, I don't really understand this part: "it makes a nonsense of the security of login accounting to allow programs outwith the Trusted Computing Base to write/update the login database." – Anthony Geoghegan Jul 6 '18 at 10:28
  • It just occurred to me that outwith may have been intended as outwit. Maybe, undermine might be a better word - but I'm not particularly familiar with the concept of Trusted Computing Base. – Anthony Geoghegan Jul 6 '18 at 13:55

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.