ps command in Linux / Ubuntu
ps command in Linux / Ubuntu, which lets us to view the current running processes.its is also usefull in killing a process or to view which applications other users are running.
ps stands as abbreviation for “Process Status”
Syntax
ps [options]
1. Simple process selection :
Shows the processes for the current shell
ps
Where,
PID the unique process ID
TTY terminal type that the user is logged into
TIME amount of CPU in minutes and seconds that the process has been running
CMD name of the command that launched the process
Also please note TIME 00:00:00 means the total accumulated CPU utilization time for any process and 00:00:00 indicates no CPU time has been given by the kernel till now.
4. List Process Info
ps -A
We will use -u option for this detailed information.
5. Show process by name or process id
ps -C apache2
Here we will use -C parameter and process name for filter operation.
ps -p 2048,2184
We will use the -p option and PID in order to filter.
Often ps is used with grep like ps -aux | grep command to get the list of process with the given command.
ps -ef | grep apache2
The grep command helps you filter the results from the ps command.
7. How to list all processes for a group
To list all processes by group use the -g option. This supports the group ID or name.
ps -g users
Now Some Advance Usage of ps command
Now below command will search for processes by the name apache2 and construct a tree and display detailed information.
ps -f --forest -C apache2
Turn ps into an realtime process viewer
watch -n 1 'ps -e -o pid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head -15'
The output on my desktop is something like this.
The output would be updated every 1 second to refresh the stats. However do not think that this is similar to top.
How to search for an kill a process
To kill a process first we need to find process id (PID) then using the kill command to terminate the process. In the following example ps is piped to grep
Example
ps -ef | grep tomcat
now we got pid of tomcat
sudo kill -9 PID
You May Also Enjoy Reading This …