man ps
says:
If you want a repetitive update of the selection and the displayed information, use top(1) instead.
... however, in some cases, I don't like the output of top
- I would instead like to have the output exactly the same as ps axf
:
$ ps axf
PID TTY STAT TIME COMMAND
2 ? S 0:00 [kthreadd]
3 ? S 0:06 \_ [ksoftirqd/0]
6 ? S 0:00 \_ [migration/0]
11 ? S< 0:00 \_ [cpuset]
12 ? S< 0:00 \_ [khelper]
13 ? S< 0:00 \_ [netns]
15 ? S 0:00 \_ [sync_supers]
16 ? S 0:00 \_ [bdi-default]
17 ? S< 0:00 \_ [kintegrityd]
18 ? S< 0:00 \_ [kblockd]
19 ? S< 0:00 \_ [kacpid]
20 ? S< 0:00 \_ [kacpi_notify]
21 ? S< 0:00 \_ [kacpi_hotplug]
22 ? S< 0:00 \_ [ata_sff]
23 ? S 0:00 \_ [khubd]
24 ? S< 0:00 \_ [md]
26 ? S 0:00 \_ [khungtaskd]
27 ? S 0:01 \_ [kswapd0]
28 ? SN 0:00 \_ [ksmd]
29 ? S 0:00 \_ [fsnotify_mark]
30 ? S< 0:00 \_ [aio]
31 ? S 0:00 \_ [ecryptfs-kthrea]
32 ? S< 0:00 \_ [crypto]
36 ? S< 0:00 \_ [kthrotld]
38 ? S 0:00 \_ [scsi_eh_0]
39 ? S 0:00 \_ [scsi_eh_1]
40 ? S< 0:00 \_ [kmpathd]
...
Now, running ps axf
repeatedly is not a problem (plenty of suggestions on Repeat a Unix command every x seconds forever - Unix & Linux Stack Exchange); however, as the above snippet shows, its output can be quite larger than the size of a terminal window.
So I was wondering - is there a program which can run a command repeatedly, and collect its output, and display it in something like an ncurses
window? I'd ideally like to set ps axf
to refresh at half a second - and I'd like to have scrolling (given that the output will overflow terminal window bounds), however, such that if the text display starts vertically from, say, line 6 on top, it stays at that position - even if the latest output of the command has more (or less) lines of text in it than the previous one.
I hoped screen
may do something like this, but then, I don't think it implements any scrolling behavior... Is there a program out there that does something like this?
1 Answer 1
This particular point of contention has come up here on U&L a couple of times before. Mainly around the tool watch
, which doesn't have this feature.
- How can I scroll within the output of my watch command?
- Is there a way to dynamically refresh the less command?
- Is there a paging version of
watch
?
Generally you have 3 options.
- Use
watch
with this limitation - Use a alternative script (mywatch.sh or watchless) or tool such as
pwatch
- Use an alternative tool to
ps
, such ashtop
oratop
So I would encourage you to let go of ps
and use it for what it is. A quick way to get at the state of things when in a shell. If you want to "watch" the state of the various processes running on a system use a tool such as htop
. It has a "tree" view similar to the one you're asking about and you can scroll through the output.
NOTE: To toggle "treeview" simply hit the t key while in htop
.
ss of htop
Kernel thread in htop?
If you'd like to see Kernel Thread in htop
you can enable them. They're disabled by default. There are 2 ways to do this. You can toggle them on and off using the keyborad shortcut Shift+K.
It's also accessible from the Setup menu, F2. Once you're in the Setup menu you can use the arrow keys (←,↑,→,↓) to move around, and to mark things you use the Spacebar. Once you've picked your changes, hit Esc to get out.
ss #2
NOTE: In the above screenshot, #1 shows you're in the Setup menu. #2 shows we've used the ↑ and ↓ arrow keys to move to Display Options. To access these options, you'd use the ← and → arrow keys to move over to the "choices" part of the menu, followed by ↑ and ↓ arrows to "select". Once you've selected an option you can use the Spacebar to toggle it.
References
-
Many thanks for that answer @slm - it explains well that what is a "state of the art" for this problem (which I wasn't aware of) - so I accepted it for now. I got both
atop
andhtop
- and it seems, none of them reportkthreadd
and its "dependencies"; and that is a part of what I need this for (and which is why I wanted a "generic" application which gives one acurses
scrolling window). Thanks again - cheers!sdaau– sdaau2014年02月10日 12:17:07 +00:00Commented Feb 10, 2014 at 12:17 -
PS: pwatch seems to be able to do what I wanted; except it needs handlers for proper termination of
ncurses
; it also (currently) terminates prematurely if one goes above a certain line in theps axf
output (though scrolling works). But otherwise, that was what I was looking for. Cheers!sdaau– sdaau2014年02月10日 12:46:09 +00:00Commented Feb 10, 2014 at 12:46 -
PSS: Multitail linked from one of the pages on this answer also looks neat, but it needs to be built from source (for me,
libncursesw5-dev
was also needed); but unfortunately it can scroll "only the last 100 lines", and refresh of the command kills the scroll window (as of v6.0).sdaau– sdaau2014年02月10日 13:05:33 +00:00Commented Feb 10, 2014 at 13:05 -
@sdaau - you can control the scrollback using the
-mb x
andM lines
switches onmultitail
. I only have 5.2.13 in repos.2014年02月10日 13:10:01 +00:00Commented Feb 10, 2014 at 13:10 -
@sdaau - Did you try something like this?
multitail -R 2 -l "ps axf"
.2014年02月10日 13:15:27 +00:00Commented Feb 10, 2014 at 13:15
watch -n 0.5 ps axf
do what you want?watch
but unfortunately there's no scrolling as you describe it there.watch
, although, at least it keeps the start of output on top of terminal...C-a ESC
, then you can scroll).