From a20b0b853dffadb65d34271361226fabebc8b280 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 31 Mar 2006 21:57:06 +0000 Subject: [PATCH] more example stuff --- bindings/java/examples/ProcessState.java | 7 ++- bindings/java/examples/ServiceStatus.java | 56 +++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 bindings/java/examples/ServiceStatus.java diff --git a/bindings/java/examples/ProcessState.java b/bindings/java/examples/ProcessState.java index 911553b1..aaaecb28 100644 --- a/bindings/java/examples/ProcessState.java +++ b/bindings/java/examples/ProcessState.java @@ -1,6 +1,9 @@ import net.hyperic.sigar.*; /* + +Example to show the process state for a given pid. + Compile the example: % javac -classpath sigar-bin/lib/sigar.jar ProcessState.java @@ -15,6 +18,9 @@ bash: Sleeping State of emacs editor used to write the example: % java -classpath sigar-bin/lib/sigar.jar:. ProcessState 2673 emacs: Suspended + +See also: examples/Ps.java, examples/Top.java + */ public class ProcessState { @@ -52,7 +58,6 @@ public class ProcessState { ProcState procState = sigar.getProcState(pid); String state; - System.out.println(procState.getName() + ": " + getStateString(procState.getState())); diff --git a/bindings/java/examples/ServiceStatus.java b/bindings/java/examples/ServiceStatus.java new file mode 100644 index 00000000..a2d43601 --- /dev/null +++ b/bindings/java/examples/ServiceStatus.java @@ -0,0 +1,56 @@ +import java.util.Arrays; +import java.util.List; +import net.hyperic.sigar.win32.Service; +import net.hyperic.sigar.win32.Win32Exception; + +/* + +Example to show the status of a Windows services. + +Compile the example: +% javac -classpath sigar-bin/lib/sigar.jar ServiceStatus.java + +Status of all services: +% java -classpath sigar-bin/lib/sigar.jar:. ServiceStatus +Alerter: Stopped +ALG: Running +Apache Tomcat 4.1: Stopped +Apache2: Running +... + +Status of a specific service: +% java -classpath sigar-bin/lib/sigar.jar:. ServiceStatus Eventlog +Eventlog: Running + +See also: examples/Win32Service.java + +*/ +public class ServiceStatus { + + private static void printStatus(String name) + throws Win32Exception { + + Service service = new Service(name); + System.out.println(name + ": " + + service.getStatusString()); + service.close(); + } + + public static void main(String[] args) + throws Exception { + + List services; + String name; + + if (args.length == 0) { + services = Service.getServiceNames(); + } + else { + services = Arrays.asList(args); + } + + for (int i=0; i