Created
October 2, 2015 02:11
-
-
Save moznion/b1ea9179f5d0c41921a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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__ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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