Shortest Way to List a Running Process

command lineprocessps

I often need to check if a process is running, so I use one of these:

ps aux | grep myprocess
ps -Fe | grep myprocess
top
pgrep myprocess (only shows the PID)
pkill myprocess (if I want to kill it)

All of the above commands work well but, is there a shorter command to do this?
Any answer is appreciated, but the chosen one needs to be…

  • A built in solution, as I work with many different devices.
  • Enables to use a pattern.
  • Gives you similar information than ps aux.
  • Shorter than what we already know.

Thanks

Best Answer

I think what you're asking for doesn't exist so why not write a little bash function or script that does exactly what you want?

function p {
    ps aux | awk -v s="$@" 'NR>1 && $11~s'
}

Stick that in your ~/.bash_functions (or wherever is called by ~/.bashrc) and call source ~/.bashrc to reload it and you should be able to run:

$ p firefox
oli       5992 11.2  4.2 2856240 1044104 ?     Sl   Jun17 313:56 /usr/lib/firefox/firefox

The expression will take a regex which makes it doubly handy. And p on its own will give you a full listing.