Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

w

Show who is logged on and what they are doing.

Description

Reads the system utmp database to enumerate logged-in user sessions, then correlates each session against /proc to report login time, idle time, cumulative CPU time on the session’s tty (JCPU), CPU time of the foreground process (PCPU), and the command that process is running.

The header line matches uptime(1): current wall-clock time, system uptime, number of logged-in users, and the 1/5/15-minute load averages.

Inputs

  • /var/run/utmp – one record per login session. Each entry’s struct layout follows the system libc’s utmpx; entry stride is detected via std::mem::size_of::<libc::utmpx>() to stay correct across glibc architectures (384 bytes on x86_64, 400 bytes on aarch64).
  • /proc/[pid]/stattty_nr (controlling terminal device), tpgid (foreground process group), utime + stime (cumulative CPU ticks), comm.
  • /proc/[pid]/cmdline – shown in the WHAT column when non-empty.
  • /proc/uptime, /proc/loadavg – header line.
  • /dev/<tty>st_rdev (matched against tty_nr for session membership) and atime/mtime (used to derive idle time).

The session source is utmp only. Modern procps-ng builds compiled with systemd support read sessions from systemd-logind instead, which can yield a different session list on systemd hosts. Logind support is a planned follow-up.

Arguments

FlagDescription
[USER]Show information for the named user only
-h, --no-headerDon’t print the header line
-u, --no-currentDon’t try to identify the foreground process; report info for the utmp entry’s own pid
-s, --shortShort format – omit LOGIN@, JCPU, PCPU
-f, --fromShow the FROM (remote host or display) column
-i, --ip-addrIn FROM, show an IP address rather than hostname (best-effort DNS resolution)
-p, --pidsIn WHAT, prefix the command with loginpid/whatpid
-o, --old-styleBlank IDLE for sessions idle less than one minute

Behavior

Header line

 HH:MM:SS up <uptime>,  N user[s],  load average: A, B, C

<uptime> is D days, H:MM, H:MM, or M min depending on magnitude.

Columns

Default layout (no -f, no -s):

USER     TTY      LOGIN@   IDLE   JCPU  PCPU WHAT
ColumnSource / meaning
USERutmp ut_user (truncated to PROCPS_USERLEN, default 8)
TTYutmp ut_line (basename of the controlling tty, e.g. tty2, pts/0)
FROMutmp ut_host (only with -f; truncated to PROCPS_FROMLEN, default 16)
LOGIN@utmp ut_tv formatted by age (see below)
IDLEnow – max(atime, mtime) of /dev/<tty>; ? when the tty cannot be statted
JCPUsum of utime + stime over all processes with the same tty_nr as the session’s tty
PCPUutime + stime of the foreground process group leader on the tty
WHATcmdline of the foreground process; falls back to comm, then to -

When the session has no resolvable tty (empty ut_line or no matching device), JCPU/PCPU/WHAT fall back to the utmp entry’s own ut_pid.

LOGIN@ format

AgeFormatExample
Same calendar dayHH:MM14:32
Within 7 daysWeekdayHH (3-letter weekday + 2-digit hour)Sat01
OlderDDMmmYY25Apr26

Idle / CPU-time format

The IDLE column and the JCPU/PCPU columns share the same duration format:

MagnitudeFormatExample
< 60sS.SSs (seconds with two decimals)0.06s
< 60minMM:SS54:42
< 24hH:MMm (hours:minutes with m suffix)1:31m
>= 24hNdays3days

Environment

VariableDefaultEffect
PROCPS_USERLEN8Width of the USER column
PROCPS_FROMLEN16Width of the FROM column

Exit codes

CodeMeaning
0Success
1Failure (cannot read /var/run/utmp)