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

1 Answer 1

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.

6
  • 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
    Commented Jul 23, 2011 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
    Commented Jul 24, 2011 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
    Commented Jul 24, 2011 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. Commented Jul 24, 2011 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
    Commented Jul 25, 2011 at 21:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .