Skip to content

Instantly share code, notes, and snippets.

@moznion
Created October 2, 2015 02:11
Show Gist options
  • Save moznion/b1ea9179f5d0c41921a4 to your computer and use it in GitHub Desktop.
Save moznion/b1ea9179f5d0c41921a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
print "daemon pid: $$\n";
while (1) {
my $pid = fork;
die "Failed to fork" unless defined $pid;
if ($pid <= 0) {
# child
exec("java Sig");
}
# parent
$SIG{HUP} = sub {
kill 'HUP', $pid;
};
waitpid $pid, 0;
}
__END__
public class Sig {
public static void main(String... args) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
System.out.println("java finished");
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}));
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment