2

Are there any tools that improve the readability of ps in the same spirit as ack for grep?

This would be especially on OS X where ps does not even have options such as --sort user.

So far the nicest formatting I could come up with is

alias p="ps -m -o pid,user,%mem,args"

and pa="p -a" px="p -x", but I would like to, for example:

  1. format the memory footprint better (e.g. KB, MB, ...)
  2. sort by user name or filter with p <user>
  3. only show {fore,back}ground processes with p {fg,bg}
  4. draw the pstree hierarchy without being overwhelmed
  5. color the output meaningfully
Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
Paolo
  • 1,535

1 Answers1

6

Proctools provides advanced searching features: pgrep allows easy and accurate searching by command name, and pfind has many search criteria in the guise of find for files. See also pgrep and pkill alternatives on mac os x? Both tools have some options to control what is displayed, though ps has more; you can use them together with ps:

ps -o pid,ppid,tty,time,comm -p $(pgrep -d, -u paolo,root -x vim)

For sorting, in many cases, you can pipe the ps output into sort:

… | sort -k 3 -k1n

For further output postprocessing, awk can help.

… | awk '$3 ~ /^tty/ {$0 = "\033[32m" $0 "\033[0m"} 1'

There is also htop, a better replacement for top (available for OSX). It's full-screen, not command-line based. You can configure colors and filters in limited but powerful ways. There's a tree display.

  • 1
    htop also works with a mouse (it uses ncurses?) -- you can click on the different columns, and it will sort by that column. – laebshade Jul 23 '11 at 17:33
  • 2
    so I guess the answer is no: no perl monger or equivalent has gone through the pain of writing a more humane tool like they did for ack — too bad, thanks for the links. – Paolo Jul 24 '11 at 13:47
  • @Paolo: I was going to answer with htop but I see Gilles included it. How is that NOT what you are looking for? – Caleb Jul 24 '11 at 14:39
  • @Caleb htop is a full-screen application, intended for interactive use. You can't redirect its output to a file, for example; and you can't specify the display format on the command line (you could make a wrapper that generates a .htoprc, I suppose). It satisfies all of Paolo's numbered requirements, but not the premise of being a command-line, batch application. It's one of the several partial solutions in my answer; I don't have anything to propose that meets all the requirements. – Gilles 'SO- stop being evil' Jul 24 '11 at 15:10
  • Exactly. If any batch application bubbles up from the bottom of the internet and is reported here, then I would like to award the accepted answer. That is, unless this is considered bad etiquette, I'm new to this community. – Paolo Jul 25 '11 at 21:14
  • @Paolo My answer is partial, so you are morally entitled to not mark it as accepted. If someone ever finds a better answer, they'll be slightly more inclined to contribute if they see that you're still expecting answers. (You can, however, change which answer is accepted at any time.) So I suggest that you leave the answer unaccepted, but it's up to you. Note that on some Stack Exchange sites, people will pressure you to accept your answers and sometimes refuse to help you if you don't, but we aren't like that on [unix.se]. – Gilles 'SO- stop being evil' Jul 25 '11 at 21:28