How to check the uptime of a process (or an application) running in Linux machine using shell script?
Here’s how you can check the uptime of a process using shell script:
# Application’s PID
app_pid=`ps ax | grep [app-pattern]| grep -v grep | awk ‘{print $1}’`
echo $app_pid# Application’s Uptime
app_uptime=`ps -p $app_pid -o “%t” | tail -1`
echo $app_uptime
Eg. If you like to know the uptime of an Apache ActiveMQ instance,
# Get ActiveMQ PID
activemq_pid=`ps ax | grep apache-activemq | grep -v grep | awk ‘{print $1}’`
echo $activemq_pid# Get ActiveMQ Uptime
activemq_uptime=`ps -p $activemq_pid -o “%t” | tail -1`
echo $activemq_uptime
About this entry
You’re currently reading “How to check the uptime of a process (or an application) running in Linux machine using shell script?,” an entry on Singaram's Tech Musings
- Published:
- June 15, 2011 / 3:26 PM
- Category:
- Coding tips
- Tags:
- Apache ActiveMQ, AWK, Uptime

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