• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

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!
0
dshrenik
Asked:
dshrenik
  • 3
  • 3
1 Solution
 
CEHJCommented:
0
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now