Skip to content

Code examples

Markus Enax edited this page Oct 1, 2016 · 9 revisions

Example 1: Platform architecture

import de.thjom.java.systemd.Manager;
import de.thjom.java.systemd.Systemd;

try (Systemd systemd = Systemd.get()) {
    Manager manager = systemd.getManager();

    String arch = manager.getArchitecture();
}
catch (final DBusException e) {
    e.printStackTrace();
}

Example 2: PID of running unit (here 'service')

import de.thjom.java.systemd.Service;
import de.thjom.java.systemd.Systemd;

try (Systemd systemd = Systemd.get()) {
    Service avahi = systemd.getManager().getService("avahi-daemon");

    long pid = avahi.getMainPID();
}
catch (final DBusException e) {
    e.printStackTrace();
}

Clone this wiki locally