ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Distribution: Ubuntu, ElemntaryOS, Linux Mint, openSUSE, Xubuntu
Check if program is running
I'm just starting to look into shell scripts. I would like to know if there is a CLI way of checking whether or not a program is running (something along the lines of 'thisCommand -kaffeine' returning a boolean value)?
I cannot remember a more elegant way (sure some guru around here can provide us with a fascinating solution); but this does the trick:
some_variable=`ps -C kaffeine|grep -v PID`
then if "some_variable" is empty, kaffeine is not running; if "some_variable" is not empty, kaffeine is running.
It could be that there is an option in "ps" doing exactly what you look for; do "man ps" and have fun reading it.
edit: or more transparent: substitute "grep -v PID" by "grep kaffeine"