signals

perl signal processing only works once when sighandler calls subroutine

非 Y 不嫁゛ 提交于 2019-12-22 11:27:37
问题 Setup: kernel: 4.1.16-v7+ OS: armv7l GNU/Linux (mostly debian) This is perl 5, version 20, subversion 2 (v5.20.2) built for arm-linux-gnueabihf-thread-multi-64int A larger perl code has a part of external process which sometimes does not respond within a certain timelimit. When this error occurs the "main" subroutine gets restarted via signal_handler command "restartservice" During debugging this issue i found numerous descriptions about signal handling and especially reinitialising a signal

prctl(PR_SET_PDEATHSIG) race condition

旧街凉风 提交于 2019-12-22 10:37:25
问题 As I understand, the best way to achieve terminating a child process when its parent dies is via prctl(PR_SET_PDEATHSIG) (at least on Linux): How to make child process die after parent exits? There is one caveat to this mentioned in man prctl : This value is cleared for the child of a fork(2) and (since Linux 2.4.36 / 2.6.23) when executing a set-user-ID or set-group-ID binary, or a binary that has associated capabilities (see capabilities(7)). This value is preserved across execve(2). So,

Interprocess synchronization using signals in c, linux

北慕城南 提交于 2019-12-22 10:30:12
问题 Process A forks say 4 child processes. exec() is used to replace the code of the children. The children initialize and have to wait for the parent to create all of the 4 of them. Then the parent sends a sigusr1 to each child process in order for them to start processing. The parent waits for all the children to complete procesing. When a child finishes its work it sends a sigusr2 to the parent. When the parent receives all the sigusr2 signals it continues with execution, merging the

“Proper” way to handle signals other than SIGINT in Python?

爱⌒轻易说出口 提交于 2019-12-22 10:23:54
问题 I had some Python code that needed to be able to handle SIGINT. For this purpose I used something like this: def mymethod(*params): obj = MyObj(params) try: obj.do_some_long_stuff() except KeyboardInterrupt: obj.cleanup() Awesome and really straightforward. Yay, Python is great! However, I now need to also handle other signals, namely SIGTSTP and SIGQUIT. What I'm trying to do is something similar. Here's some pseudocode demonstrating what I'm trying to do with SIGTSTP (I hope it's clear

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

Interrupting c/c++ readline with signals

允我心安 提交于 2019-12-22 10:07:58
问题 I'm attempting to interrupt readline with signals (SIGUSR1), but obviously if the signal isn't handled, the program exits, when handling, it readline proceeds as though nothing has happened. Is readline supposed to be able to be interrupted using signals. I got the idea from this other question: force exit from readline() function #include <stdio.h> #include <unistd.h> #include <signal.h> #include <readline/readline.h> #include <pthread.h> pthread_t main_id; void *thread_main(void* arg) {

sending a signal to a background process

感情迁移 提交于 2019-12-22 10:07:38
问题 Which signal should I send to a background process to move it foreground? SIGTTIN, SIGTOU or...? 回答1: gurudoglu. I think your request's response is here : http://en.wikipedia.org/wiki/SIGCONT http://en.wikipedia.org/wiki/SIGTTIN http://en.wikipedia.org/wiki/SIGTTOU 回答2: It's not signals which directly control whether jobs are foreground or background. The jobs are under the control of a shell (usually). For example, under bash , if you execute: pax> sleep 3600 & pax> jobs you will see output

Android and JNI real time clock

╄→гoц情女王★ 提交于 2019-12-22 09:37:08
问题 I got a problem with a mini Android application and the use of real time clock signals in a C (JNI) function. It seems like Android UI doesn't like real time signals from timers instanced in a C function. In the following PoC , a timer trigger a signal 5 times per second and if the signal is triggered while the UI is updating, the application crashes. If i don't start the timer => no crash If i don't put anything on UI => no crash I wrote this little PoC to evidence the behaviour. Java part

python signals, interrupting system calls

三世轮回 提交于 2019-12-22 08:38:46
问题 I am writing a program in python. I wish to read from stdin, and handle sigchld. I want to handle either input as it comes in, without spinning (speculatively sampling for input). I can't catch sys-call interrupted by signal on every call I make. Am I going about this the wrong way? Can I get this to work without try/except? My main worry is not the try/except I have in the code so far. But all the hundreds I will need in ever other line of code in the program. It does not seem modular to me.

Determine which signal caused EINTR?

这一生的挚爱 提交于 2019-12-22 08:34:19
问题 I am running an epoll loop and sometimes my call to epoll_wait returns -1 with errno set to EINTR. Sometimes, I want this to end the epoll loop, like in the case of SIGTERM or SIGINT. But I have this code compiled with the -pg flag, so periodic SIGPROF (27) signals are raised that stop my loop. So... is it possible to switch on the signum so that I can determine when to exit vs. continue? I would like to avoid anything that employs the use of a global to keep track of the most recent signal