we may some time need to know, whether the process is running or not.
For example:
our application is deployed in Linux system and runs in tomcat server.
we use tomcat scripts to deploy the application (start/stop shell script).
it would always be good to verify whether the application is deployed and running in the server.
command to use
$ ps -ef
Note: ps - provide the snapshot of process status running in Linux/ unix os
- e and -f are generally known as switch for the command or options or selection.
-e will select all the process running
-f will provide full format listing of the process.
there are more number of options for "ps" command use the below command to explore it
$ man ps
or
$ ps -help
On executing the command
Command #1
$ ps -ef
sample out put:
UID PID PPID C STIME TTY TIME CMD
root 1170 1139 0 09:42 pts/0 00:00:00 su - user1
user1 6021 1171 0 13:35 pts/0 00:00:00 ps -ef
user2 6022 1171 0 13:35 pts/0 00:00:00 -ksh
The Command #1 can output can be piped to grep to filter specific line to be displayed.
Example
Command #2
$ ps -ef | gerp user2
sample out put
user2 6022 1171 0 13:35 pts/0 00:00:00 -ksh
only returns the line that contains user2 (as we are greping for it in linux).
additionally use the below command combination to get the header also
Command #3
$ ps -ef | grep -e user2 -e PID
sample out put
UID PID PPID C STIME TTY TIME CMD
user2 6022 1171 0 13:35 pts/0 00:00:00 -ksh
If the process needs to be killed we should use the PID number of the process. PID stands for process-id, every process in Linux has an process-id. For more information, we need to understand the Linux OS structure.
to kill the running process use the below command
$ kill -9 6022
kill - command to kill the process
-9 is the option which force kills
PID process id which should be killed, in this case its 6022.
Note: always be cautious on using the kill command when killing a process.
No comments:
Post a Comment