Check status of a service

Please let me know how I can check if a particular service is running through java code on both a Windows machine and a Mac.

Thanks!
dshrenikAsked:
Who is Participating?
 
dshrenikAuthor Commented:
Could you provide some sample code? Thanks!
0
 
dshrenikAuthor Commented:
For example, if I want to check if mysql is running, how do I figure that out?

This code is not working:

try {
        	int timeout = 2000;
        	InetAddress[] addresses = InetAddress.getAllByName("mysql");
        	for (InetAddress address : addresses) {
        		if (address.isReachable(timeout))
        			System.out.printf("%s is reachable%n", address);
        		else
        			System.out.printf("%s could not be contacted%n", address);
        	}
        } catch (Exception e) {
        	System.out.printf("Unknown host: %s%n", "www.java2s.com");
        }

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
CEHJCommented:
To be reasonably sure: connect to the default mysql port. To be 100% sure, you'd have to become a (successful) mysql client
0
 
dshrenikAuthor Commented:
I had to use "mysql.net".

Thanks!
0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.