shutdown-hook

Is there something like finally() in Go just opposite to what init()?

岁酱吖の 提交于 2019-12-05 04:55:10
Is there something in Go which do just opposite to what init() do inside a package? icza This was discussed before by the Go team, and the conclusion was not to add support for it. Quoting minux : Personally, I prefer the style where program exit is handled exactly same as program crash. I believe no matter how hard you try, your program can still crash under some unforeseen situations; for example, memory shortage can bring any well-behave Go program to a crash, and there is nothing you can do about it; so it's better to design for them. If you follow this, you won't feel the need for atexit

how to check if exit is clean in a shutdown function in PHP?

Deadly 提交于 2019-12-05 00:50:29
问题 How can I test if exit is clean in a shutdown function in PHP? By clean exit I mean that the script was not terminated due to an error. 回答1: Its a good question, for the moment I only have this idea: register a shutdown function like this: function shutdown() { if (defined('END_REACHED') { echo 'Script executed with no error', PHP_EOL; } } register_shutdown_function('shutdown'); With auto_append_file add an additional file to the very end of every script execution which sets an constant. Your

Cygwin CTRL-C (Signal Interrupts) not working properly - JVM Shutdown Hooks not starting

ⅰ亾dé卋堺 提交于 2019-12-04 22:56:37
I'm working on a Java application that utilises shutdown hooks in order to clean up on termination/interruption of the program, but I've noticed that Cygwin's implementation of CTRL-C doesn't seem to trigger the shutdown hooks. On the surface it appears to have interrupted the process, relinquishing control back to the command line, however the process' shutdown hooks are not triggered at all so cleanup does not occur. In cmd they get caught, but due to various constraints I need to somehow get them working in Cygwin. Is there any way to fire a SIGINT at a running process through Cygwin at all

Configure Linux to Suspend to Disk on ACPI G2 Soft Off — so Google Compute Engine can suspend and restore preemptible machine via disk

怎甘沉沦 提交于 2019-12-04 12:26:30
问题 Google Compute Engine rents all size Linux VMs from 1 core to 64 cores at various prices. There are "preempt-able" instances for about 1/4 the price of guaranteed instances, but the the preempt-able instances can be terminated at any time (with an ACPI G2 soft off warning and ~ 30 secs until hard cutoff). Although you can provide a startup and shutdown script, the usual approach seems to lead to the unnecessary overhead of having to then create additional software to allow calculations to be

How to shutdown java application correctly from C# one

99封情书 提交于 2019-12-04 02:06:21
问题 I have java application which shutdowns correctly when i use CTRL-C , java application saves all data before shutdown. Now i trying to shutdown this java application from my C# console application using Process.Close() , but application dont't save any data when i use this, i also tried Process.CloseMainWindow() but using this nothing is happening, and also Process.Kill() but using this process just killed, without any savining. How can i raise shutdown hook on java application from C#

What happens if System.exit is called from a shutdown hook?

a 夏天 提交于 2019-12-04 01:43:54
I have a rather complicated shutdown in Java - there's a lot of clean up work to do. In particular I'm trying to figure out how to error handle from a shutdown hook thread. My code includes this currently: try { return shutdownPromise = doShutdown(); } catch (Throwable exc) { logger.error("An exception was thrown while shutting down the application.", exc); System.exit(1); return null; } When I originally wrote this I essentially thought, an error in shutdown should just go straight to exit . But exit is not so low level; it calls the shutdown hooks. So I thought - What does calling exit from

Configure Linux to Suspend to Disk on ACPI G2 Soft Off — so Google Compute Engine can suspend and restore preemptible machine via disk

时光怂恿深爱的人放手 提交于 2019-12-03 07:57:57
Google Compute Engine rents all size Linux VMs from 1 core to 64 cores at various prices. There are "preempt-able" instances for about 1/4 the price of guaranteed instances, but the the preempt-able instances can be terminated at any time (with an ACPI G2 soft off warning and ~ 30 secs until hard cutoff). Although you can provide a startup and shutdown script, the usual approach seems to lead to the unnecessary overhead of having to then create additional software to allow calculations to be interrupted, and to manage partial results of calculations whereas the suspend-to-disk/restore-from

shutdown hook doesn't fire when running with “lein run”

两盒软妹~` 提交于 2019-12-03 06:03:49
I have the following code: (ns test-hook.core) (defn -main [] (.addShutdownHook (Runtime/getRuntime) (Thread. #(println "shutdown"))) (println "start") (doseq [i (range 1 6)] (Thread/sleep 1000) (println i))) and the following project.clj (defproject test-hook "1.0.0-SNAPSHOT" :aot :all :main test-hook.core :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.2.0"]]) when I run it with "lein run" the shutdown hook only gets executed on normal program execution, not when receiving SIGINT (Ctrl-C) the same code when ran outside of lein successfully executes the shutdown

How to ensure a piece of code is run before exiting a java application

余生长醉 提交于 2019-12-01 03:33:01
问题 I'm using a licensed API which has a method to acquire/release a license object from a license server that has a finite number of licenses. At the beginning of my application, I call the method to acquire the license, but I want to make sure that this gets released even if my program terminates/crashes abruptly (exceptions, SIGTERM, etc). Is the shutdown hook the best way to approach this issue? 回答1: @thedan is correct about hard JVM crashes. If a JVM crashes hard or it gets a SIGKILL, it won

PHP's register_shutdown_function to fire when a script is killed from the command line?

笑着哭i 提交于 2019-12-01 03:04:48
Is it possible to invoke a function when a cron process is killed from the command line (via Ctrl+c) or with the kill command? I have tried register_shutdown_function() , but it doesn't seem to be invoked when the script is killed, but does get invoked when the script ends normally. I am trying to log the result to a file and update a database value when a cron instance is killed automatically (ie. has been running too long). Pekka 웃 According to a comment in the manual on register_shutdown_function() , this can be done the following way: When using CLI ( and perhaps command line without CLI -