Find uptime of 'apache2'

来源:互联网 发布:打电话变女声软件 编辑:程序博客网 时间:2024/04/30 17:02



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

$ ps -eo comm,etime | grep httpdhttpd            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 httpdhttpd                 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 LISTENtcp        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 grepapache    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.



0 0