signals

In what order should I send signals to gracefully shutdown processes?

試著忘記壹切 提交于 2019-11-26 17:06:58
In a comment on this answer of another question , the commenter says: don’t use kill -9 unless absolutely necessary! SIGKILL can’t be trapped so the killed program can’t run any shutdown routines to e.g. erase temporary files. First try HUP (1), then INT (2), then QUIT (3) I agree in principle about SIGKILL , but the rest is news to me. Given that the default signal sent by kill is SIGTERM , I would expect it is the most-commonly expected signal for graceful shutdown of an arbitrary process. Also, I have seen SIGHUP used for non-terminating reasons, such as telling a daemon "re-read your

How to Handle SIGABRT signal?

懵懂的女人 提交于 2019-11-26 17:04:35
问题 Here is the code on which I set my handler for SIGABRT signal then I call abort() but handler does not get trigered, instead program gets aborted, why? #include <iostream> #include <csignal> using namespace std; void Triger(int x) { cout << "Function triger" << endl; } int main() { signal(SIGABRT, Triger); abort(); cin.ignore(); return 0; } PROGRAM OUTPUT: 回答1: As others have said, you cannot have abort() return and allow execution to continue normally. What you can do however is protect a

Oracle Pro*C/OCI install handlers for SIGSEGV/SIGABRT and friends - why, and how to disable?

蹲街弑〆低调 提交于 2019-11-26 17:02:16
问题 When using Pro*C (a embedded SQL preprocessor from Oracle for C-Code) or OCI I noticed that the connect/init routine installs some signal handlers. That means before a EXEC SQL CONNECT :username IDENTIFIED BY :password USING :dbspec ; or a OCIEnvNlsCreate() I can verify that for example those signals have following handlers: No NAME Pointer SA_SIGINFO SIG_DFL SIG_IGN ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― 1 SIGHUP (nil) false true false 2 SIGINT (nil)

Are sig_atomic_t and std::atomic<> interchangable?

大兔子大兔子 提交于 2019-11-26 16:45:47
问题 As per the title. Can I use std::atomic<> in a signal handler or does sig_atomic_t provide other compiler features? 回答1: n3376 1.9/6 When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects which are neither — of type volatile std::sig_atomic_t nor — lock-free atomic objects (29.4) are unspecified during the execution of the signal handler, and the value of any object not in either of these two categories that is modified by the handler becomes

Dealing with Floating Point exceptions

拥有回忆 提交于 2019-11-26 16:36:21
问题 I am not sure how to deal with floating point exceptions in either C or C++. From wiki, there are following types of floating point exceptions: IEEE 754 specifies five arithmetic errors that are to be recorded in "sticky bits" (by default; note that trapping and other alternatives are optional and, if provided, non-default). * inexact, set if the rounded (and returned) value is different from the mathematically exact result of the operation. * underflow, set if the rounded value is tiny (as

How to get cell service signal strength in Android?

冷暖自知 提交于 2019-11-26 16:32:49
I am trying to write a very simple Android application that checks the signal strength of the current cell. So far, I have only found something called getNeighboringCellInfo() , but I'm not really sure if that includes the current cell. How do I get the CURRENT cell signal strength in Android? Does getNeighborCellInfo() get the current cell? It doesn't seem like it based on the results that I have been able to get with it. Here's my current code: List<NeighboringCellInfo> n = tm.getNeighboringCellInfo(); //Construct the string String s = ""; int rss = 0; int cid = 0; for (NeighboringCellInfo

Accurately reading of iPhone signal strength

时光总嘲笑我的痴心妄想 提交于 2019-11-26 16:18:18
问题 There are a few questions on this already, but nothing in them seems to provide accurate results. I need to determine simply if the phone is connected to a cell network at a given moment. http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html This class seems to be documented incorrectly, returning values for mobileCountryCode, isoCountryCode and mobileNetworkCode where no SIM is installed to the phone. carrierName indicates a

executing default signal handler

早过忘川 提交于 2019-11-26 15:47:41
问题 I have written an application where i have registered number of signal handler for different signals in linux . After process receives the signal the control is transferred to the signal handler i had registered. In this signal handler i do some work which i need to do, and then i would like to call the default signal hander i.e SIF_DFL or SIG_IGN . However, SIG_DFL and SIG_ING are both macros which expand to numeric values 0 and 1 respectively, which are invalid function addresses. IS there

Capture SIGINT in Java

穿精又带淫゛_ 提交于 2019-11-26 15:21:43
What is the best way to capture a kill signal in java without using JNI. I did discover the sun.misc.Signal and the sun.misc.SignalHandler and the warning of the possibility of being removed in the future releases. Would using JNI to call a c lib be the only option i have? The way to handle this would be to register a shutdown hook. If you use ( SIGINT ) kill -2 will cause the program to gracefully exit and run the shutdown hooks. Registers a new virtual-machine shutdown hook. The Java virtual machine shuts down in response to two kinds of events: The program exits normally, when the last non

Catch Ctrl+C / SIGINT and exit multiprocesses gracefully in python

只谈情不闲聊 提交于 2019-11-26 15:14:00
问题 How do I catch a Ctrl+C in multiprocess python program and exit all processes gracefully, I need the solution to work both on unix and windows. I've tried the following: import multiprocessing import time import signal import sys jobs = [] def worker(): signal.signal(signal.SIGINT, signal_handler) while(True): time.sleep(1.1234) print "Working..." def signal_handler(signal, frame): print 'You pressed Ctrl+C!' # for p in jobs: # p.terminate() sys.exit(0) if __name__ == "__main__": for i in