Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I check if a certain application is running by its file name? Or if that's not possible, then by its command line? I know "pkill" has the option "-f" but I don't need to kill it, just check.


I want to get the status of a certain application(s) only in bash, preferable if I don't need to filter the output to lookup up the status of the app I want to check the status of.

If that matters, it's a python or ruby script, I need to check the status for them both.

share|improve this question
Depends. Is that a GUI app ? or console ? – Serg Feb 12 at 5:28
@Serg, console. – Mr. Mister Feb 12 at 5:29
up vote 2 down vote accepted


Since you've asked how to check if a process is running or not when you know its name , then it's a simple pgrep operation. Alternatively, one could use ps and specify state options for formating

$ ps --no-headers -C firefox -o args,state                     
/usr/lib/firefox/firefox    R

State code is on the right. From man ps you can know their meaning:

       D    uninterruptible sleep (usually IO)
       R    running or runnable (on run queue)
       S    interruptible sleep (waiting for an event to complete)
       T    stopped, either by a job control signal or because it is
            being traced
       W    paging (not valid since the 2.6.xx kernel)
       X    dead (should never be seen)
       Z    defunct ("zombie") process, terminated but not reaped by
            its parent


Most of the time console apps run with their own name. If it's a script, with a !# line on the top, it will run with an interpreter specified with that line, for instance a bash script:

$ ps -ef | grep batmon
root      2108     1  0 22:22 ?        00:00:00 /bin/bash /home/xieerqi/bin/

However there are scripts that server as wrapper for other applications.For instance gnome-terminal is actually a script which calls gnome-terminal.real

What you always put an app into background , which will tell you a pid of that process

$ bin/ &                                              
[1] 3224

You then can use kill PID (for example here kill 3224) to close app directly, or use ps to find its name:

$ ps --no-headers -p 3224 -o %a                                
/bin/bash bin/

In general, pkill can search for the names given without -f , which stands for full name. You could also search using pgrep appNamePartial

share|improve this answer
ты что-то намудрил. нужно просто проверить запущен ли питон скрипт по имени его файла. все. как? – Mr. Mister Feb 12 at 5:49
Я в самом начале так и написал - скрипт будет запущен той программой для которой он написан - тут нет ничего сложного. – Serg Feb 12 at 5:52
обновил мой вопрос. – Mr. Mister Feb 12 at 5:56
@Mr.Mister Gentlemen, please could we enjoy the discussion? – Jacob Vlijm Feb 12 at 5:59
Note that the advantage of pgrep or pgrep -f is that it filters itself out of the search. (like ps -ef | grep <scriptname> | grep -v grep) – Jacob Vlijm Feb 12 at 6:08

If you want to live track the processes you can have the famous command:


but you want it by filename so you will need to add a parameter as:

top -c
share|improve this answer
Yup, that's good too. In general any app that can monitor processes or search for process names can be used. top, htop, ps , pgrep - doesn't matter, it's all applicable – Serg Feb 12 at 5:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.