1

Currently, I am learning some UNIX command and encountered several unexplained questions. Thanks for your answering.

  1. When I run the command w from the terminal, I got some messages shown in the picture below. I know s000 stands for the terminal in which I typed the command w. But I am confused about the tty whose name is console and by which, it said, I logged into the system. And it said that console had been idle for some time. Can I switch to console to activate this tty to make it no longer idle?

  2. I also did another experiment trying to kick off the guest user who was logging in. I knew I can kill the bash process that the guest was running, but somehow I am having a problem killing the console the guest was running. How can I completely kick off the guest without rebooting the computer? I can not kill the console. The root of this problem is pretty much the same as the first one: what does "console" stand for? Absolutely it does not stand for the terminal in which I typed the command w.

  3. This problem can also be found on Linux system such as Ubuntu 14.04 with the latter naming the console with number such as 0 or 1. I wonder what 0 or 1 in tty column means. But I can be sure that they have similar meaning with console.

here is the image

Giacomo1968
  • 58,727
Han XIAO
  • 155

1 Answers1

1

I’m not familiar with macOS, but I expect the concepts are pretty similar to those in Linux.  This is somewhat of an oversimplification, but basically, in this context, the “console” refers to the entire computer.  Or, to be somewhat more specific, the display and the human input devices (keyboard, pointing device(s), etc.)   (Network logins are excluded from the “console”.)

When you login to your computer (locally, not via the network), you are logging in to the console.

Now you’re obviously familiar with terminals — windows in which you can run commands, like ls and w.  When you log in to the console, it automagically runs a command (or a group of commands) that gives you the windowed interface that you’re accustomed to.  Some operating systems make the mechanism by which this happens visible, and sometimes even adjustable; others do it entirely “under the hood”.

Since the console doesn’t run any commands, except for the window system itself, it appears to be idle.  On most operating systems (and I expect that macOS is one of them), the only was to switch to the console is to exit from the window system — but that returns you to the console, which then automagically logs you out.

There’s another wrinkle:

  • The w command reads a system file, formats the data nicely for a person to look at it, and writes it to the standard output.
  • An entry gets written to the file whenever anybody logs in at the console or over the network.  Some (most? all?) systems also write an entry when the user at the console starts a new terminal window.
  • Entries normally get erased when a user logs out or closes a terminal window.
  • The key word in the above bullet is “normally”.  In some cases, if you kill a process (especially if you do it as superuser), you may interfere with the mechanism that erases the old data.  Thus, w might report information that is no longer valid.

If you don’t know how to use ps, you should learn.  You can use it instead of w, but it’s probably better to use them together.  Use w to give you a road map of what to look for in the ps output.  Don’t blindly believe everything w tells you; believe only the information that you can verify with ps.  For example, if you have killed all the “guest” processes, and w still says that “guest” is logged in, it’s probably giving you stale, invalid information.


You might find What is the difference between shell, console, and terminal? and What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? to be worthwhile reading.