A PID is an acronym for process identification number on a Linux or Unix-like operating system. A PID is automatically assigned to each process when it is created. A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system.
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
Find out process pid
Type the following ps command to display all running process:
# ps -aux | less
OR
# ps aux | less
Where,
- A : Select all processes
- u : Select all processes on a terminal, including those of other users
- x : Select processes without controlling ttys
By use ps command we can get process name
# ps aux | grep {process-name}
For example lets find httpd process (nginx pid) is running or not:
# ps aux | grep nginx root      1494 0.0 0.0 103328  900 pts/1   S+  10:41  0:00 grep nginx root     65271 0.0 0.1 108940 2176 ?       Ss  08:02  0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx    65274 0.0 0.1 109368 3192 ?       S    08:02  0:00 nginx: worker process nginx    65275 0.0 0.1 109368 2864 ?       S   08:02  0:00 nginx: worker process
Find the process ID of a running program using pidof
pidof command finds the process ids (pids) of the named programs. It prints those ids 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 nginx
65275 65274 65271
To see every process on the system
# ps -A # ps -e
To See every process except those running as root
# ps -U root -u root -N
To See process run by user vivek
# ps -u orange
top command
The top program provides a dynamic real-time view of a running system. Type the top at command prompt:
Read More: Linux server performance Monitoring Tools
# top
To quit press q, for help press h.
To display a tree of processes
pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.
# pstree
To Get info about threads
Type the following command:
# ps -eLf # ps axms
To Get security info
Type the following command:
# ps -eo euser,ruser,suser,fuser,f,comm,label # ps axZ # ps -eM
To Save Process Snapshot to a file
Type the following command:
# top -b -n1 > /tmp/process.log
Or you can email result to yourself:
# top -b -n1 | mail -s 'Process snapshot' you@example.com
Lookup process
Use pgrep command. pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to screen. For example;
# pgrep nginx
3356
Following command will list the process called sshd which is owned by a user called root:
# pgrep -u root sshd
htop
htop is interactive process viewer just like top, but allows to scroll the list vertically and horizontally to see all processes and their full command lines. Tasks related to processes (killing, renicing) can be done without entering their PIDs. To install htop type command:
# apt-get install htop
or
# yum install htop
Now type the htop command at the shell prompt:
# htop
atop
The program atop is an interactive monitor to view the load on a Linux system. It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, i.e. cpu, memory, disk and network. It also shows which processes are responsible for the indicated load with respect to cpu – and memory load on process level; disk- and network load is only shown per process if a kernel patch has been installed. Type the following command to start atop:
# atop