Asaf Maimon
Asaf Maimon

Reputation: 71

Find if a process (Server) is running on unix

I have a server (Java) that is running on UNIX.

I'm trying to develop some application that will "sense" if the state of the server has been changed and notify me by mail.

I want to know how can I do it? If there is some event or other way to sense the change, (by the way, sending the eMail is not the problem).

I was thinking on Java code that will run in an infinite loop and will check if the process is running, but it seems to me a bad way.

Any idea will be accepted. Thank you.

Upvotes: 0

Views: 3628

Answers (3)

Some programmer dude
Some programmer dude

Reputation: 409482

You can monitor the servers process id to check if it's still running. That won't detect if the server is in an infinite loop somewhere, which can be done by having the server process write a timestamp to a file in regular intervals. If the timestamp is older than twice the interval, it can be considered dead.

Upvotes: 0

Anantha Sharma
Anantha Sharma

Reputation: 10108

you can set a timer event on a java program (either using cron or quartz)

in the program you can check to see if a particular process is running.. you can use ps -e | grep java

or you can get the java program to sendout jmx messages which can be used track the status of the app (again this depends if you can change the app on the server).

Upvotes: 1

Nicocube
Nicocube

Reputation: 2992

Sensing the state of a Java server is to be prepared before launch. I think you should take a look at Metrics project for example: http://metrics.codahale.com/

Upvotes: 0

Related Questions