Monday, April 29, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1299  / 1 Year ago, sat, january 21, 2023, 5:01:23

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


More From » command-line

 Answers
2

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.


[#24551] Saturday, January 21, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
splenueak

Total Points: 448
Total Questions: 118
Total Answers: 110

Location: Vanuatu
Member since Mon, Oct 3, 2022
2 Years ago
splenueak questions
Tue, Aug 24, 21, 09:07, 3 Years ago
Sat, Apr 23, 22, 15:14, 2 Years ago
Thu, Jun 10, 21, 17:43, 3 Years ago
Mon, Sep 20, 21, 15:19, 3 Years ago
;