How to tell if a certain program is running?

Marius Gedminas marius at pov.lt
Fri Jul 6 10:47:19 UTC 2007


On Fri, Jul 06, 2007 at 07:38:17PM +0900, Craig Hagerman wrote:
> I am wondering if there is a simple way to programatically tell if a
> given program is running. I want to write a bash script to check if a
> program is running, then if not start it.

The most reliable solution is start-stop-daemon.  It's a bit complicated
to use, read the manual page.

> My first idea was to try to return grep the output from 'ps ax' but
> even if a program isin't running grep will return the request you just
> made. I am sure there is a more elegant way I don't know about.

Try pidof or pgrep instead.

Marius Gedminas
-- 
I am a computer. I am dumber than any human and smarter than any administrator.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20070706/2f95bdf9/attachment.sig>


More information about the ubuntu-users mailing list