Sunday, 15 January 2012

ubuntu - Why doesn't Java's .addShutdownHook work for Ctrl-C on BeagleBone Black? Is there a workaround? -



ubuntu - Why doesn't Java's .addShutdownHook work for Ctrl-C on BeagleBone Black? Is there a workaround? -

problem

i have run next clojure code on both ubuntu development machine , beaglebone black, , can confirm works on former not latter.

(defn setup-shutdown-hook! [f] (.addshutdownhook (runtime/getruntime) (thread. f))) (setup-shutdown-hook! (fn [] (println "i no more"))) (defn -main [] (doseq [i (range)] (thread/sleep 1000) (println "staying alive")))

on bbb, shutdown hook does work appropriately in case of "natural" shutdowns, not on ctrl-c. on ubuntu machine, seems work.

is there explanation different behavior? java versions? scheme level differences? there workaround getting desired behavior?

system details

ubuntu:

java version "1.7.0_65" openjdk runtime environment (icedtea 2.5.2) (7u65-2.5.2-3~14.04) openjdk 64-bit server vm (build 24.65-b04, mixed mode)

beaglebone (running angstrom; connected via ssh):

> java -version java version "1.7.0_60" java(tm) se runtime environment (build 1.7.0_60-b19) java hotspot(tm) client vm (build 24.60-b09, mixed mode) > uname -a linux beaglebone 3.8.13 #1 smp wed sep 4 09:09:32 cest 2013 armv7l gnu/linux

p.s. of familiar java not clojure, clojure code above hooks java methods through it's interop. can test trans

oh dear... there's no mystery here. lazy, cheated bit, , ran on ubuntu machine lein exec instead of lein run (as did on bbb) ._. apparently, things seem behave differently way...

more point of how desired behavior, lein trampoline run -m <ns> trick. problem appears since using lein run runs application within nested jvm, leiningen process catches ctrl-c instead of application code. using lein trampoline detaches application code jvm such catches ctrl-c, , runs shutdown code desired.

thanks this post showing me light, , stack overflow it's wonderful "related" questions.

java ubuntu clojure beagleboneblack shutdown-hook

No comments:

Post a Comment