signal-handling

Intel CPU OpenCL in Mono killed by SIGXCPU (Ubuntu)

白昼怎懂夜的黑 提交于 2020-01-24 19:54:27
问题 Some time ago I wrote simple boids simulation using OpenCL (was school assignment), using C#, Cloo for OpenCL and OpenTK for OpenGL output. I tested it on Windows7 with AMD CPU implementation of OpenCL and on friend's NVidia. Now I tried it on Linux (Ubuntu 12.04). I installed amd app sdk and intel sdk. It compiled ok, reference CPU implementation is working fine with graphic output. But when I try to run OpenCL version, it runs for about 1 second (showing what seems like valid output in

How to execute a handler function before quit the program when receiving kill signal from“killall” or “kill -p pid”?

核能气质少年 提交于 2020-01-11 12:35:21
问题 I have the following code: #include <stdio.h> #include <stdlib.h> #include <pthread.h> pthread_t test_thread; void *thread_test_run (void *v) { int i=1; while(1) { printf("into thread %d\r\n",i); i++; sleep(1); } return NULL } int main() { pthread_create(&test_thread, NULL, &thread_test_run, NULL); sleep (20); pthread_cancel(test_thread); sleep(100); // In this period (before the finish of myprogram), // I execute killall to kill myprogram // I want to add a signal handle function to //

Python break from socket receive on SIGINT

橙三吉。 提交于 2020-01-04 09:40:08
问题 I'm working on a program that receives data from a socket, and when a signal is sent, I want to be able to break from the receive. What I have now: class Killer: die = False def __init__(self): signal.signal(signal.SIGINT, self.terminate) signal.signal(signal.SIGTERM, self.terminate) def terminate(self, signum, frame): print ("caught " + str(signum)) self.die = True; sock = socket.socket() # Generic socket setup while (~killer.die): #generic data setup sock.receive(data) sock.shutdown(socket

Signal handling in OpenMP parallel program

折月煮酒 提交于 2020-01-01 09:14:12
问题 I have a program which uses POSIX timer ( timer_create() ). Essentially the program sets a timer and starts performing some lengthy (potentially infinite) computation. When the timer expires and a signal handler is called, the handler prints the best result yet that has been computed and quits the program. I consider doing the computation in parallel using OpenMP, because it should speed it up. In pthreads, there are special functions for example for setting signal masks for my threads or so.

Python - Trap all signals

删除回忆录丶 提交于 2019-12-28 02:00:08
问题 In python 2.6 under Linux, I can use the following to handle a TERM signal: import signal def handleSigTERM(): shutdown() signal.signal(signal.SIGTERM, handleSigTERM) Is there any way to setup a handler for all signals received by the process, other than just setting them up one-at-a-time? 回答1: You could just loop through the signals in the signal module and set them up. for i in [x for x in dir(signal) if x.startswith("SIG")]: try: signum = getattr(signal,i) signal.signal(signum,sighandler)

Async serial communication in non-canonical (raw) mode and generating SIGIO in linux/osx

别来无恙 提交于 2019-12-25 08:34:15
问题 To start off, I'm having trouble getting my serial device to generate a SIGIO when data is ready to be read. I am trying to write a simple serial interface to communicate to a micro using a usb to serial adapter. I'd like to keep this interface as similar to one you would find in a micro (interrupt driven, using callbacks) and so I decided to go the way of catching a SIGIO signal instead of using a separate thread or constant non-blocking serial reads. Here is my initialization code (most of

Blocking signals causes boost process not to work

你离开我真会死。 提交于 2019-12-25 03:51:42
问题 In the code below the class Process can run a process using boost process in asynchronous mode and can kill it if it times out. Now in order to shut it down, I block all the signals in all threads and create a specific thread signal_thread to handle signals. On doing this the program stops working. I guess this is probably because the parent process can no longer receive the signal SIGCHLD and know that the child process has finished executing. #include <iostream> #include <csignal> #include

is it possible to set a promise in a signal handler?

妖精的绣舞 提交于 2019-12-24 01:01:44
问题 I was looking for a way to stop a thread that perform a task every 2 seconds. I decided to try to use a std::promise/future so that the thread can exit immediately when the promise is set. #include <future> #include <iostream> #include <chrono> #include <csignal> std::promise<void> stop; int main() { std::signal(SIGINT, [] (int) { stop.set_value(); } ); auto future = stop.get_future(); while (future.wait_for(std::chrono::seconds(1)) != std::future_status::ready) { std::cout << "I'm still

How to resolve REG_EIP undeclared (First use in this function ) error on Linux 32 bit machine?

妖精的绣舞 提交于 2019-12-23 12:54:21
问题 I have been coming across errors in compilation of my signal handler program written in C language with gcc in displaying the dumped register values after occurance of Segmentation fault. When i tried to access it using the code: void print_registers(FILE *fd, ucontext_t *ctx, bool fpu = false) { const char *flags_str[] = { "CF", 0, "PF", 0, "AF", 0, "ZF", "SF", "TP", "IF", "DF", "OF", 0, 0, "NT", 0, "RF", "VM", "AC", "VIF", "VIP", "ID" }; greg_t *regs = ctx->uc_mcontext.gregs; void *eip[1] =

How to deal with errno and signal handler in Linux?

夙愿已清 提交于 2019-12-22 10:16:10
问题 When we write a signal handler that may change the errno, should we save errno at the beginning of the signal handler and restore the errno at the end of it? Just like below: void signal_handler(int signo){ int temp_errno = errno; *** //code here may change the errno errno = temp_errno; } 回答1: The glibc documentation says: signal handlers that call functions that may set errno or modify the floating-point environment must save their original values, and restore them before returning. So go