I am interested in finding out the last time a process was scheduled to run. That is, how long it has been sleeping, since it last ran. When was it last active? Basically, a generalization of what the
w
command prints, but for all processes, and not just the login shells.
To make this concrete: the w
command prints a list of user sessions, when they logged in, and how long they've been idle. For example:
$ w
17:17:04 up 10 days, 17:35, 2 users, load average: 0.28, 0.26, 0.30
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
linas tty7 :0 31Jan25 10days 13:27m 2.09s mate-session
linas pts/7 10.70.70.2 16:54 7:08 0.07s 0.07s -bash
This says that linas
logged in on pts/7
twenty-three minutes ago (17:17 minus 16:54) and did some typing at the keyboard, burning a trivial amount of CPU time, and then did nothing at all for seven minutes and eight seconds. In the kernel, the process bash
is in interruptible sleep, waiting for keyboard input, and has been like that for 7:08
mm:ss.
How can I get this info for *all* processes? Or, if that's not available, then all ptys? So, pts/1
though /6
also have bash attached to them, but they're ... idle. No one is typing into them, right now.
It seems like the ps
command should be able to show this, but I can't figure it out. Perhaps this info is in /proc/
but if so, not clear where. The GPT/LLM chatbots all cluelessly provide nothing but wrong answers (insisting on ps -o etime
which is something else entirely.)
Asked by Linas
(205 rep)
Feb 11, 2025, 11:41 PM
Last activity: Feb 12, 2025, 12:10 AM
Last activity: Feb 12, 2025, 12:10 AM