These are some of the ps aliases and functions I have found useful over the years.

Aliases

I’ve always loved aliases. They make long and unmemorable commands memorable and they’re a pretty good, self-documenting way to keep track of those Hero commands that do something great but that you would struggle to remember. Here are a few that I developed working with Cloudera java processes and complex web server setups.

The following show you the top 20 memory hogs. The first just sorts and limits the usual output. The pmem alias is a lot more useful for a quick view

alias ptop='ps aux --sort=-%mem | head -n 20'
alias pmem='ps aux --sort=-%mem | head -n 20 | awk '\''{print $1, $4, $11}'\'' | column -t'

Similarly, this one shows top cpu hogs

alias pscpu='ps aux --sort=-%cpu | head -n 20 | awk '\''{print $1, $3, $11}'\'' | column -t'

The forest view shows subprocesses in a friendly way

alias pfor='ps auxf --forest'

Finally, what are my longest running proceses?

alias psme='ps -u $(whoami) -o pid,etime,cmd --sort=-etime | head'

bash functions

Sometimes you want to do something that the ps program alone isn’t capable of doing. For me it was displaying a space between each process. I was working on a deep dive and after staring at wall after wall of grey dense grey text I found myself doing it manually in an output file. That’s always a sure sign that it’s time to write a function if not a standalone script.

pss function

This function inserts a blank line between processes. much more readable.

# Runs ps and displays each process separated by a blank line to improve readability
pss() {
  ps aux | awk '1; { print "" }'
}

psss function

This function provides more separation and uses color to make it even more readable. This one is probably better for deep dives than daily use but I have found it useful plenty of times.

# Pretty print ps output, with optional filtering
psss() {
  local filter="${1:-}"

  echo "🧠 Showing processes${filter:+ matching: '$filter'}"
  echo "─────────────────────────────────────────────"

  ps auxww --sort=-%mem | {
    if [[ -n "$filter" ]]; then
      grep -i --color=always -- "$filter"
    else
      cat
    fi
  } | awk '
    BEGIN {
      GREEN = "\033[1;32m"; BLUE = "\033[1;34m"; RED = "\033[1;31m";
      YELLOW = "\033[1;33m"; CYAN = "\033[1;36m"; RESET = "\033[0m";
    }
    {
      print GREEN "USER:" RESET " " $1;
      print BLUE "PID:" RESET "  " $2 "  " RED "CPU:" RESET " " $3 "  " YELLOW "MEM:" RESET " " $4;
      printf CYAN "CMD:" RESET "  ";
      for (i = 11; i <= NF; ++i) printf "%s ", $i;
      print "\n";
    }
  '
}

It’s output looks like this:

psss output


Conclusion

May your zombie processes be few in number