Whats Up Doc
Bill Nash
plug-discuss@lists.plug.phoenix.az.us
Fri, 8 Nov 2002 17:57:06 +0000 (UTC)
On Fri, 8 Nov 2002, Austin Godber wrote:
> George Gambill wrote:
> > From the command line (RH8) how do I findout the status (is it installed, is
> > it running) of such things as:
>
> There is a command called service that runs the init script status
> option (see later discussion). So if you want to see the status of your
> httpd service:
>
> > /sbin/service httpd status
> httpd (pid 6742 6741 6740 6739 6738 6737 6736 6735 894) is running...
>
> There is a --status-all option that gives you the status of all services
> in /etc/init.d
Yow, this seems to be a strictly RedHat solution to the problem,
though. More generic approaches to checking on the status of a service
would include the use of 'netstat' and 'lsof'.
netstat will show you the state of socket connections to and from your
machine. This is generally handy when looking for processes (like httpd or
ssh) that open sockets for connections.
`netstat -a` will gift you with output like this:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:9090 *:* LISTEN
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
This is a greatly pared down example that doesn't show active connections,
to keep it relevant to the question at hand. You'll notice some sockets
are numeric, while others are named. This comes of keeping /etc/services
up to date should you be doing anything outside 'standard' areas.
In the case of the process listening on port 9090, netstat gives you no
indicator as to what that process is, since /etc/services doesn't contain
an entry for it. 'lsof', short for 'list open files' can give you more
insight, as it will show you what processes have files open, including
*filehandles* and sockets.
[root@kraken ~]# lsof | grep LISTEN
wwasher 1086 nobody 5u IPv4 2138 TCP *:9090
(LISTEN)
wwasher 1087 nobody 5u IPv4 2138 TCP *:9090
(LISTEN)
mysqld 2178 mysql 3u IPv4 3673 TCP *:mysql
(LISTEN)
mysqld 2179 mysql 3u IPv4 3673 TCP *:mysql
(LISTEN)
Again, contents of /etc/services apply to reduce pain. There are a lot of
other uses for these two utilities, but for those not running Redhat, this
is a much more generic *nix solution to the question. Relevant man pages
can offer more detail on these tools.
- billn