Issue
How to get only the process ID for a specified process name in Linux?
ps -ef|grep java
test 31372 31265 0 13:41 pts/1 00:00:00 grep java
Based on the process id I will write some logic. So how do I get only the process id for a specific process name.
Sample program:
PIDS= ps -ef|grep java
if [ -z "$PIDS" ]; then
echo "nothing"
else
mail test@domain.example
fi
Solution
You can use:
ps -ef | grep '[j]ava'
Or if pgrep
is available then better to use:
pgrep -f java
Answered By - anubhava Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.