Find uptime of 'apache2' [closed]

You can use ps -eo comm,etime for example:

$ ps -eo comm,etime | grep httpd
httpd            5-01:40:22

This shows the elapsed time since the process was started. Mine is showing 5 days, 1 hr, 40 mins, 22 secs.

And after a restart:

$ ps -eo comm,etime | grep httpd
httpd                 00:07

In a graceful restart, if an apache process is still serving a connection it won't be killed until it finishes, so if it's a large download to a slow host, it may linger for a while until it completes.

I did snip most of the output as it shows each forked process, but you will have a general overview of how long it has been running.


I suspect there are lots of apache-version-specific ways to do this, but one generally-valid (and slightly brute-force) way is as follows.

Find the PID of the process that has the port open; it will have been the first one started:

[root@lory ~]# netstat -apn|grep -w 80|grep LISTEN
tcp        0      0 :::80                       :::*                        LISTEN      2903/httpd          

The netstat command requires privilege, so run as root or under sudo. In this case the PID is 2903. Then find how long that process has been running:

[root@lory ~]# ps auxww|grep 2903|grep -v grep
apache    2903  0.0  1.0 413316 39972 ?        S    Oct23   0:42 /usr/sbin/httpd

In this case, the start time is Oct 23, so I've been running a couple of days. You might get a field like 11:15, in which case it's a time of day, today, so you know the restart's worked.