signal-handling

What constitutes asynchronous-safeness

依然范特西╮ 提交于 2019-12-17 16:45:47
问题 It is said that you should only call asynchronous-safe functions inside a signal handler. My question is, what constitutes asynchronous-safeness ? A function which is both reentrant and thread safe is asynchronous-safe I guess? Or No? 回答1: Re-entrance and thread safety has a little or nothing to do with this. Side effects, state and interruption of those functions are facts that matter. asynchronous-safe function [GNU Pth] A function is asynchronous-safe, or asynchronous-signal safe, if it

Is it possible to terminate only the one thread on receiving a SIGSEGV?

喜欢而已 提交于 2019-12-13 15:43:22
问题 I have an application which starts multiple threads. I am using a signal handler to catch the signals. I don't want my application to quit on SIGSEGV ; I want to terminate only the thread that incurred the signal, and to continue the flow of the full application in the other threads. Is it possible? 回答1: If a SIGSEGV happens, it indicates that your program has already invoked undefined behavior, i.e. the state of the entire program is undefined/indeterminate/invalid. In practice it's possible

Handling CTRL-C in dummy shell

余生颓废 提交于 2019-12-13 02:50:50
问题 I'm writing a dummy shell that should not terminate when the user types ctrl-C but should just generate a new prompt line. Currently, my shell does not terminate when I type ctrl-C but it still does not print the new prompt line. Do you know why this is the case and how I can fix this? My code is below: #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <unistd.h> #include <sys/wait.h> #include <signal.h> #define BUFFER_SIZE 1<<16 #define ARRAY_SIZE 1<<16

Signal handling and check pointing for mpif90

◇◆丶佛笑我妖孽 提交于 2019-12-13 02:39:25
问题 I have written a code for trapping the signal for CTRL+C for gfortran and it works. program trap external trap_term call signal(2, trap_term) call sleep(60) end program trap function trap_term() integer::trap_term print*,'done' call exit(trap_term) end function trap_term How would one write exactly same thing for mpif90 ? Also, what is the best way to include checkpoints and restart (probably automatic) the code (from where left before) in parallel processors. This is required because I have

How do you intercept a keyboard interrupt (CTRL-C) in Jython?

孤街浪徒 提交于 2019-12-12 23:02:09
问题 This is what I've tried... from sun.misc import Signal from sun.misc import SignalHandler class InterruptHandler(SignalHandler): def handle(self): print "Shutting down server..." Signal.handle(Signal("INT"),InterruptHandler()) It's based on this http://www.javaspecialists.co.za/archive/Issue043.html, but evidently I'm missing something. 回答1: Looks like a bug in Jython. There are some workarounds given there. 回答2: I was facing similar problem before. This is how I get it resolved. First,

Backtracing on Linux 64 bit from Signal Handler with malloc/free on callstack

我与影子孤独终老i 提交于 2019-12-12 12:15:01
问题 Below is an example of source I want to use on a machine running "Red Hat Enterprise Linux 5.5 (Tikanga) Kernel 2.6.18-194.el5xen x86_64" OS. The general idea is that I want to have backtrace of some thread, so I am raising a SIGUSR1 signal for that thread and a handler does a backtrace() call. In my scenario as below, FrameTwo function calls malloc and free in a loop. Whenever the signal is raised for this particular thread and free or malloc is on the callstack, the progream crashes when

Threaded perl and signal handlers

混江龙づ霸主 提交于 2019-12-12 09:54:46
问题 I am using the Thread::Pool module in perl to parallelize some perl code. This process takes a while and occasionally I will kill it from the command line with a SIGINT. Doing so causes the program to end abruptly, as I expected. This leaves some messy temporary files around, so I'd like to install a signal handler. I did this: sub INT_Handler{ #clean up code exit(1); } $SIG{'INT'} = 'INT_handler'; before creating the thread pool and starting the threads. Now when I send the SIGINT, the

compile errors using signal.h in Linux [duplicate]

痴心易碎 提交于 2019-12-12 09:31:26
问题 This question already has answers here : struct sigaction incomplete error (2 answers) Closed 5 years ago . I'm writing a shell program that must handle signals. My relevant signal handling related code is as follows: #include <signal.h> ... #include <sys/types.h> ... void installSigactions( int, struct sigaction* ); void handler_function( int signal_id ); ... /*define signal table*/ struct sigaction signal_action; /*insert handler function*/ signal_action.sa_handler = handler_function; /

Unix/Linux: Handler of SIGCONT/SIGTSTP

蓝咒 提交于 2019-12-11 17:40:22
问题 I'm currently writting program using signals, and I've got this trouble: How can I change state of executing program to stopped/running without sending SIGSTOP / SIGCONT ? I understand, that I need to use: void add_to_runqueue (struct task_struct * p) and void del_from_runqueue (struct task_struct * p) but how to obtain structure task_struct of currently running process? Also: if it is all that I need to do (calling those 2 functions). Thanks in advance! 回答1: These functions would be kernel

How to catch JNI Crashes as exceptions using Signal handling based mechanism in Java [duplicate]

为君一笑 提交于 2019-12-11 17:01:37
问题 This question already has answers here : How to catch JNI/Java Exception (2 answers) Closed 4 years ago . I developed a Java tool and it has many JNI functions, I am getting JNI crashes often. Is there any possibility to avoid those crashes or to catch these crashes as exceptions. I surfed internet and found it is possible through signal processing, signal chanining, sigaction(), etc. But I could not get a reliable source to direct me. Please do guide me on this. 回答1: JNI exceptions are