On 10:38 24 Jun 2003, Dan Bar Dov <[EMAIL PROTECTED]> wrote: | This is probably a historical question, yet I'd like to re-open it. | What is the best way to determine if a process is up? | | Best way = portable across linux distributions, quick, relies on minimum | availability of resources | Checkproc for example is used in init.d scripts on SuSE, but is not a | command in RedHat distribs. A chkproc function is used by RedHat for the | same purpose, but is not available except for init scripts.
If you know its process id and have the rights to signal it (i.e. you're root or your-uid == its-uid) then: if kill -0 $pid 2>/dev/null then it is up else it is not up fi For most services, a well written daemon will write a pid file (eg /var/run/daemon-name.pid) from which the pid may be obtained. | The command pidof(8) is a good candidate. Another is pgrep (a canned ps | and grep?). | Pidof is packaged in sysvinit, while pgrep is part of a "ps" package. I'm not a big fan of pidof etc. Grepping a process listing is inherently a very dodgy way of locating a process' pid. You've not guarenteed that no other command uses that name (or one sufficiently similar to match your grep pattern). If there's more than one match, which do you pick? Should you pick either? The whole thing makes me think "kludge". In principle for most things you should be able to obtain a reliable notion of the pid, usually from a /var/run/daemon.pid file or something like that. Another thing you can do is not "check the pid" but "see if the service is there. Eg examine the output of "netstat -an" for a service listening on the appropriate port (eg with awk checking for LISTEN and the port number in the right columns). Just some thoughts. Cheers, -- Cameron Simpson <[EMAIL PROTECTED]> DoD#743 http://www.cskk.ezoshosting.com/cs/ Speed costs money. How fast do you want to go? - C. Shelby -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED] https://www.redhat.com/mailman/listinfo/redhat-list