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 these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: