more example stuff
This commit is contained in:
parent
a832ba371b
commit
a20b0b853d
@ -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()));
|
||||
|
||||
|
56
bindings/java/examples/ServiceStatus.java
Normal file
56
bindings/java/examples/ServiceStatus.java
Normal file
@ -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<services.size(); i++) {
|
||||
printStatus((String)services.get(i));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user