signals

Why does a sigaction handler not handle every signal even if the SA_NODEFER flag is set?

做~自己de王妃 提交于 2019-12-06 12:28:58
I have a parent process that spawns ten child processes and uses a SIGCHILD handler to notify when a child process has died. The child processes will notify when they have started and will then exit immediately. I use the SA_NODEFER flag to prevent SIGCHLD signals to get discarded when too many are coming in. The children are all being correctly terminated and reaped, but in this script and also when terminating two at the same time via the console signals send at the same time always appear as one. #define _POSIX_C_SOURCE 200809L #include <stdio.h> #include <sys/types.h> #include <sys/wait.h>

popen()/fgets() intermittently returns incomplete output

空扰寡人 提交于 2019-12-06 09:40:56
I am experiencing a strange problem with the the popen and fgets library functions on a Linux system. A short program demonstrating the problem is below that: Installs a signal handler for SIGUSR1 . Creates a secondary thread to repeatedly send SIGUSR1 to the main thread. In the main thread, repeatedly executes a very simple shell command via popen() , gets the output via fgets() , and checks to see if the output is of the expected length. The output is unexpectedly truncated intermittently. Why? Command-line invocation example: $ gcc -Wall test.c -lpthread && ./a.out iteration 0 iteration 1

C synchronize processes using signal

冷暖自知 提交于 2019-12-06 09:16:47
Okay so I am trying to teach myself on how to do signalling, and I came across a hiccup and I can't figure out what I'm doing wrong. What is going on right now is: it is executing the parent then goes to child and then back to parent.. It's not doing what I want it to do which is execute the parent (which the user defines the amount of time it runs) then kills it then go to child and run itself at the same amount of time. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <sys/types.h> // for wait #include <sys/wait.h> // for wait void action(int); void

Issue with timer with long signal handler (SIGALARM)

白昼怎懂夜的黑 提交于 2019-12-06 09:02:18
问题 There is a timer which sends out signal SIGALARM every 1 sec. A signal handler which sleeps 2 sec is registered. What happens? Specifically, I have following code, in which the process runs multiple threads. It's quite interesting that with this long signal handler, it looks other threads are blocked from execution... Can anyone explain why this is the case? #include <unistd.h> #include <stdio.h> #include <stdlib.h> //rand #include <sys/wait.h> #include <time.h> #include <sys/time.h> #include

prctl(PR_SET_PDEATHSIG) race condition

删除回忆录丶 提交于 2019-12-06 08:28:16
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, the following code has a race condition: parent.c: #include <unistd.h> int main(int argc, char **argv) {

How do I send and receive real-time signals `sigqueue()` in Python?

人盡茶涼 提交于 2019-12-06 07:44:27
Python provides a signals module and os.kill ; does it have a facility for sigqueue() (real-time signals with attached data)? What are the alternatives? You could do it with ctypes >>> from ctypes import * >>> c = cdll.LoadLibrary("libc.so.6") >>> c.sigqueue <_FuncPtr object at 0xb7dbd77c> >>> c.sigqueue(100, 10, 0) -1 >>> You'll have to look up how to make a union in ctypes which I've never done before but I think is possible. One alternative, if no one has done it yet, would be to wrap the C library yourself - should be pretty quick and painless. Look here for more details. 来源: https:/

Signal sent to both child and parent process

点点圈 提交于 2019-12-06 07:42:01
问题 As far as I understand signals sent to a parent process should not be sent to children. So why does SIGINT reach both the child and the parent in the example below? #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void sigCatcher( int ); int main ( void ) { if (signal(SIGINT, sigCatcher) == SIG_ERR) { fprintf(stderr, "Couldn't register signal handler\n"); exit(1); } if(fork() == 0) { char *argv[] = {"find","/",".",NULL}; execvp("find",argv); } for (;;) { sleep(10

Gunicorn exits because https request from Django fails in OpenSSL

五迷三道 提交于 2019-12-06 07:31:59
问题 Here's the scenario. I have a Django app being served by Gunicorn on Linux. On certain requests it makes an https call to an external API via httplib2.request() . Sometimes that call fails in such a way that hoses OpenSSL (not sure how, but it's not my fault and doesn't really matter). OpenSSL sends a SIGABRT signal to gunicorn in this case. Gunicorn handles the SIGABRT and promptly system exits (as it should). The root issue as I see it is that OpenSSL asynchronously signals the parent

sigtimedwait() returns EAGAIN before timeout

倖福魔咒の 提交于 2019-12-06 06:59:49
问题 I'm trying to learn how to use sigtimedwait(), but I find that it's not waiting for the timeout to complete. Below it seems to return EAGAIN 4s faster than it should (1s faster per 1min of timeout): #include <signal.h> #include <syslog.h> #include <stdarg.h> #include <stddef.h> #include <errno.h> int main(int argc, char* argv[]) { setlogmask(LOG_UPTO(LOG_NOTICE)); openlog ("SIG_TIMED_WAITER", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); syslog (LOG_NOTICE, "Started"); sigset_t set;

QNetworkConfigurationManager::configurationChanged signal not getting called for ETHERNET config changes

二次信任 提交于 2019-12-06 06:13:35
QNetworkConfigurationManager::configurationChanged() signal is not getting called by the system when I am inserting a LAN cable with a valid IP(Ethernet interface). It is getting called for WLAN and USB interface but not for ETHERNET config changes Hope to get some pointers on this. 来源: https://stackoverflow.com/questions/14359657/qnetworkconfigurationmanagerconfigurationchanged-signal-not-getting-called-for