Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

I want to check the particular process in already running or not.

I refereed this Q&A.

But I didn't get any specific solution. Following is the example that I tried: I have created file and run this script on background, like sh &.

Now this file is running on background and I fire the ps aux | grep "abc" command.

Following is the output of this command:

prakash     3594  0.0  0.0   4388   820 pts/0    S+   16:44   0:00 grep --color=auto abc

After that I stop the running script and fire the same command ps aux | grep "abc" command.

But I am getting same output like:

prakash     3594  0.0  0.0   4388   820 pts/0    S+   16:44   0:00 grep --color=auto abc

Is there any other way to find the process is running or not?

share|improve this question
up vote 17 down vote accepted

Every process will be listed in the output of ps aux; whether running, sleeping, zombie or stopped.

However, in your case, since you ran the process using sh, sh is the application(shell) that is running and not Hence, ps aux will not contain the process because of which grep could not yield any result.

So, the correct way you should have used it is as:

ps aux | grep sh

This may also return you other process that are running having the string sh anywhere in their output of ps aux.

You should note that the process will be "running" when the output of ps aux has its STAT as R. If it is something other than that, it is not running at the instance you fired the command to check the running processes. The different process states can be found in the man page for ps:

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

You could as well run the top command to check if the process is running or sleeping and the amount of CPU, RAM it is consuming. (This will again list your process as sh).

However, if you do want your process to be listed as, then you should have the first line of the script you are running as:


so that the shell will know what application to use to run the script(sh in this case, change it to #!/bin/bash for bash) and then provide executable permissions to the process using:

chmod +x /path/to/

replacing /path/to/ with the location of the file and then run using


again replacing /path/to/ with the location of the file.

share|improve this answer
Thanks great answer – Prakash V Holkar May 29 '14 at 12:04
One quick question. what is stat S+ means – Prakash V Holkar May 29 '14 at 12:09
But you can find the difference between running processes and not running processes through the output of ps aux | grep filename command. – Avinash Raj May 29 '14 at 12:10
@TechGuru: It means that the process is sleeping in the foreground, refer to the manual page of ps for more. – i08in May 29 '14 at 12:10
@AvinashRaj: Yes, of course you can. – i08in May 29 '14 at 12:11

If your script is currently running, it must be shown by ps aux command. If it not shown by ps, then there may be your script execution is currently terminated.

Output of ps like this means your script is currently not running,

$ ps aux | grep
avinash   6386  0.0  0.0  15940   932 pts/16   S+   17:34   0:00 grep --color=auto

If it shows like this, which means your script is currently running.

$ ps aux | grep
avinash   6454  0.0  0.0  16616  1384 pts/16   S+   17:35   0:00 /bin/bash ./
avinash   6535  0.0  0.0  15940   932 pts/27   R+   17:35   0:00 grep --color=auto

It's all based on the contents of the script.

For example, if you create a script like this. It displays the message HI on execution. It takes a few seconds to display the output and got terminated after it produces the final result.

echo "HI"

But if your script like this,

sudo apt-get update

It takes some minutes to get the process terminated. On the meantime if you run ps aux | grep filename command, it will be shown on the output. Because the script is currently running.

share|improve this answer

The right way to check in the current bash session if a process started in background, like sh &, is already running or not is to use jobs builtin command.


$ sh &
[1] 6917
$ jobs
[1]+  Running                 sh &

That's mean that the sh process started in background is running. If the process has finished you will see something like:

[1]+  Done                    sh

If you have more processes running in background, you can restrict the output only to the sh process using:

jobs sh

See help jobs for more info.

The above method will work only in the current session of bash. But if you are in another bash session (e.g. in another terminal window or tab, or in a script), aside from:

ps aux | grep "[s]h bin/"

you can use also:

pgrep -a sh

which seems more simple to me. If you will see your typed command in the output (sh in this case), that's means that the process is still running. If not, the process has finished.

share|improve this answer

My problem with grep is that it's a whole-line parser. In your example, you're searching for "abc" but it's pulling back the instance of grep (that's looking for "abc"). A bit circular. You can filter that out but I find all that a little perverse.

I would turn to awk for a little panache.

ps aux | awk '$12==""'

awk splits the lines into fields based on whitespace (by default). Fields $11+ are the command column(s) so if the command is "sh ...", $11 will be sh and $12 will be

If you want to control the output or chain on with Bash's && and || operators, you can but you'll need to be a little more clever. grep will exit with status code 1 (technical fail, triggers ||) if nothing is found but awk will always exit code 0. We can change this by telling it to exit if it finds something and throw a 1 if it doesn't:

ps aux | awk '$12=="" {exit 0} END{exit 1}' && echo running || echo not running

Of course if you just care about writing output to the screen, you could do that all in awk:

ps aux | awk '$12=="" {print "running"; exit} END{print "not running"}'
share|improve this answer

if you simply want to check whether there is any under process then go to that directory and type ll -tr if you see .csv or .work etc at the end of the file then it means under process else not.

share|improve this answer
  • if you want to check all processes then use 'top'

  • if you want to know processes run by java then use ps -ef | grep java

  • if other process then just use ps -ef | grep xyz or simply /etc/init.d xyz status

  • if through any code like .sh then ./ status

share|improve this answer
-1 While these commands are useful under some circumstances they will still be useless to someone who doesn't know these circumstances. In each case you either don't explain them enough or your explanation is wrong. – David Foerster May 24 at 7:47

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.