Linux / UNIX: Find out or determine if process pid is running

by Vivek Gite on August 21, 2007 · 12 comments

Q. How do I find out my process is running? How do I get pid number for particular process?

A. The easiest way to find out is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

Task: Find out process pid

Simply use ps command as follows:
ps aux | grep {process-name}
For example find out if mysqld process (mysqld pid) is running or not:
$ ps aux | grep mysqld
Output:

mysql    28290  1.1  2.7 340496 56812 ?        Sl   Jul31 348:27 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock

Find the process ID of a running program using pidof

pidof command finds the process id’s (pids) of the named programs. It prints those id’s on screen. This program is on some systems used in run level change scripts, especially when the system has a System-V like rc structure. In that case these scripts are located in /etc/rc?.d, where ? is the runlevel. If the system has a start-stop-daemon (8) program that should be used instead.
# pidof mysqld
Output:

28290

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 12 comments… read them below or add one }

1 surendra kumar August 27, 2007

hay man you can use pgrep also know?
why ps -aux | grep process name?
u can use pgrep like this
pgrep process name
pgrep httpd
pgrep named
pgrep firefox
etc
if any special about your command just give me info related to it

Reply

2 Adrian B. February 10, 2009

Thanks Surendra, damn good tips

Reply

3 Adrian B. February 10, 2009

you can also use this :
$>pkill -f cruisecontrol
in a cruisecontrol process which runs under java. -f does a substring search of the process string.

Reply

4 lala September 20, 2009

man, u guys rock, trust me it helps so much, when my maya hangs.
special thanks: adrian B, pkill -f maya: wow, toogood

Reply

5 Rakesh October 2, 2009

Hi .

I have a probleam . when i start mysql it is showing MySQL manager or server PID file could not be found! [FAILED] . Starting MySQL/etc/init.d/mysql: line 159: kill: (5984) – No such process .how to solve the probleam. if any one know plz help me

Reply

6 subramanya April 23, 2010

Thank you very much for the info.. it works for me..

Reply

7 Aaron October 20, 2010

i tried using kill(pid,0) to test whether the process is existent, need to include

Aaron

Reply

8 mohsin November 29, 2010

when i reconfigure (squid -k reconfigure) squid i got error.
like this
squid: ERROR: Could not send signal 1 to process 6471: (3) No such process
how i can remove this error please help me.

Thanks in advance

Reply

9 Pinoy June 4, 2011

hanks ive been searching the net on how to find the pid of a process and this post solve my problem. thank you

Reply

10 Mikkel September 22, 2011

Bear in mind that the command itself can show up in the results. For instance:

mikkel@www ~ $ ps aux | grep ntp
root     20417  0.0  0.0   4408  1316 ?        Ss   17:30   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid
mikkel   20429  0.0  0.0   2064   572 pts/0    S+   17:30   0:00 grep --colour=auto ntp

If you only see the grep command listed, that means the named command is not running.

Reply

11 Amensan November 6, 2011

Hi,

I still can’t see my pid number for my postfix services. can’t find that. Help me. Thanks.

Using: Linux server 11.04

Reply

12 SALIM November 15, 2011

why ? mark indicating ?? while each ps -ef |grep some process

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 13 + 6 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: