How to check if a process is running or not in Linux, and execute something based on that?
#!/bin/sh
# Check if your application is running. Based on the application status, you can do whatever you want i.e. apply any logic.
# Mention SERVICE/DEPLOYABLE name.
SERVICE=’tomcat’
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE service running"
# if logic
else
echo "$SERVICE is not running"
# else logic
fi
About this entry
You’re currently reading “How to check if a process is running or not in Linux, and execute something based on that?,” an entry on Singaram's Tech Musings
- Published:
- May 17, 2011 / 5:13 PM
- Category:
- Uncategorized
- Tags:

No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]