Questions tagged [signal-handling]

In the C Standard Library, signal processing defines how a program handles various signals while it executes. A signal can report some exceptional behavior within the program (such as division by zero), or a signal can report some asynchronous event outside the program (such as someone striking an interactive attention key on a keyboard).

290 questions
5
votes
2 answers

Can I write-protect every page in the address space of a Linux process?

I'm wondering if there's a way to write-protect every page in a Linux process' address space (from inside of the process itself, by way of mprotect()). By "every page", I really mean every page of the process's address space that might be written…
Lindsey Kuper
  • 984
  • 8
  • 21
5
votes
1 answer

iphone - how to properly handle exceptional situations (signals ?)

In my iphone app, I want to provide some sort of app termination handler that will do some final work (delete some sensitive data) before the application terminates. I want to handle as much of the termination situations as possible: 1) User…
pmilosev
  • 932
  • 8
  • 20
5
votes
3 answers

Is there a way to test whether I'm in a signal handler?

I'm having to work on a logging module that can be called from various places in a large project. The problem I have is that sometimes the module may be called from code executed inside a signal handler. Normally, the logging module includes time…
Jay Walker
  • 399
  • 1
  • 10
5
votes
1 answer

Python - Handle CTRL+D with 'import signal'

I can currently handle CTRL+C via: def hand_inter(signum, frame): print 'hey, nice job.' signal.signal(signal.SIGINT, hand_inter) However I am required to also handle CTRL+D yet cannot find the appropriate "signal.CTRL+D" call for signum.
user1205371
5
votes
2 answers

Signal handler for all signal

How can I register a signal handler for ALL signal, available on the running OS, using signal(3)? My code looks like this: void sig_handler(int signum) { printf("Received signal %d\n", signum); } int main() { signal(ALL_SIGNALS_??,…
kober
  • 289
  • 5
  • 12
5
votes
1 answer

Perl Term::ReadLine::Gnu Signal Handling Difficulties

I'm using Term::ReadLine::Gnu and have run into a problem with signal handling. Given the script below and a TERM signal sent to the script, the handler for the TERM signal is not triggered until after the enter key is pressed. Using…
Sgt B
  • 1,211
  • 2
  • 11
  • 21
5
votes
1 answer

Most important signals to handle?

Recently I was working on a software written in c which had about a 3-4 thousand lines of code.When I started to get segmentation faults ,I added a SIGSEGV handler.This helped me in pin pointing the error as the handler was made to give a…
Deepthought
  • 2,815
  • 2
  • 28
  • 39
5
votes
1 answer

Can I send SIGINT to a Python subprocess on Windows?

I've got a Python script managing a gdb process on Windows, and I need to be able to send a SIGINT to the spawned process in order to halt the target process (managed by gdb) It appears that there is only SIGTERM available in Win32, but clearly if…
Ryan
  • 4,179
  • 6
  • 30
  • 31
4
votes
3 answers

sem_wait and signal handler

Why sem_wait cannot be used inside a signal handler (particularly SIGSEGV signal which is per thread)? Can someone give me an example scenario where it will crash the application? I guess sem_wait is both reentrant and thread safe, so what is the…
MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
4
votes
2 answers

Handling multiple signals

I have a question about handling a signal. Assume that if we recieve SIGINT signal, we should print "Recieved Signal". If within ten seconds the handler recieves another signal, it should print "Shutting Down" then exit with status 1. I made my code…
user1075627
  • 41
  • 1
  • 2
4
votes
2 answers

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

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…
sandeep
  • 513
  • 9
  • 17
4
votes
1 answer

Printing backtrace within signal handler in a release/optimized binary on Linux

The question is about printing a meaningful stacktrace programmatically in optimized binary. e.g. We can use backtrace, backtrace_symbols, abi::__cxa_demangle to print a stack trace. But as far as I know we need to build the binaries with compiler…
Yogesh
  • 565
  • 3
  • 21
4
votes
0 answers

How to interrupt a blocking system call function from a signal handler in Python?

I have a thread being generated from the main one which has basically an infinite loop with a system blocking function: something like: def run(self): global EXIT while not EXIT: data = self.conn.recv(1024) ... I have…
roschach
  • 8,390
  • 14
  • 74
  • 124
4
votes
1 answer

Reading SSE registers (XMM, YMM) in a signal handler

I have an x86_64 instruction "vgatherqpd %ymm7,(%r9,%ymm1,8),%ymm3" for which I need to construct the memory address at runtime in a signal handler in Linux. The signal handler ucontext uc_mcontext.gregs[XED_REG_R9] gives me the value contained in…
user1205476
  • 391
  • 1
  • 3
  • 12
4
votes
2 answers

Multi Threaded Signal Handling in C on Linux

Broad Question: What is wrong with my code so that all the signals being generated aren't being caught by the two handler threads? The unfortunate details for my poor question: I'm supposed to write some code with a main function, 3 generator…
Inquirer107
  • 53
  • 1
  • 6