signals

scanf loop, and signal handler

大憨熊 提交于 2019-12-02 08:37:51
Just learned about sigacation, also implemented another timer to make it more interesting. #include <stdio.h> #include <signal.h> #include <sys/time.h> volatile sig_atomic_t gotsignal; void handler(){ gotsignal = 1; } int main(){ struct sigaction sig; struct itimerval timer; timer.it_value.tv_sec = 5; timer.it_value.tv_usec = 0; timer.it_interval = timer.it_value; sig.sa_handler = handler; sig.sa_flags = 0; sigemptyset(&sig.sa_mask); setitimer(ITIMER_REAL, &timer, 0); sigaction(SIGALRM, &sig, NULL); int value, y = 100, x=0; while(!gotsignal && x < y){ printf("Insert a value: \n"); scanf("%d",

pyqtSignals not emitted in QThread worker

筅森魡賤 提交于 2019-12-02 08:21:53
I have an implementation of a BackgroundTask object that looks like the following: class BackgroundTask(QObject): ''' A utility class that makes running long-running tasks in a separate thread easier :type task: callable :param task: The task to run :param args: positional arguments to pass to task :param kawrgs: keyword arguments to pass to task .. warning :: There is one **MAJOR** restriction in task: It **cannot** interact with any Qt GUI objects. doing so will cause the GUI to crash. This is a limitation in Qt's threading model, not with this class's design ''' finished = pyqtSignal() #:

How to properly terminate a thread in a signal handler?

大兔子大兔子 提交于 2019-12-02 07:19:46
I want to set up a signal handler for SIGSEGV, SIGILL and possibly a few other signals that, rather than terminating the whole process, just terminates the offending thread and perhaps sets a flag somewhere so that a monitoring thread can complain and start another thread. I'm not sure there is a safe way to do this. Pthreads seems to provide functions for exiting the current thread, as well as canceling another thread, but these potentially call a bunch of at-exit handlers. Even if they don't, it seems as though there are many situations in which they are not async-signal-safe, although it is

Catching SIGINT signal to terminate a custom shell

依然范特西╮ 提交于 2019-12-02 07:17:27
问题 Hope you can help me to resolve this problem. For school I have to transform Ctrl+C to a command which doesn't shut down the shell, but he reminds through printf() that I must type exit to close the shell. I don't even know where to start. Thank a lot. 回答1: Here's a trivial implementation of handling SIGINT using sigaction which will work on posix systems. Left out error checking for brevity. The linked manual should explain about sigaction . Basically the program loops through an infinite

Differences in controlling daemons & applications

拈花ヽ惹草 提交于 2019-12-02 07:08:27
With respect to this excellent post: What's the difference between nohup and a daemon? I would like to ask the following: After launching an application from my terminal, the application keeps running either in the background or the foreground and the only thing I can do to interact with it is by sending it signals from my terminal (given that stdin is still in place). However, after a daemon process is launched, I realized that it can be controlled with other means like querying it or restarting it (arch way): # /etc/rc.d/daemon-name {start|stop|restart|status|...} Could someone explain to me

Handling Signals in an MPI Application / Gracefully exit

醉酒当歌 提交于 2019-12-02 04:44:33
问题 How can signals be handled safley in and MPI application (for example SIGUSR1 which should tell the application that its runtime has expired and should terminate in the next 10 min.) I have several constraints: Finish all parallel/serial IO first befor quitting the application! In all other circumstances the application can exit without any problem How can this be achieved safely, no deadlocks while trying to exit, and properly leaving the current context jumping back to main() and calling

SIGCHLD is sent on SIGCONT on Linux but not on macOS

六月ゝ 毕业季﹏ 提交于 2019-12-02 04:04:07
In the main process I listen to SIGCHLD: signal(SIGCHLD, &my_handler); Then I fork() , execv() and let it run in background (/bin/cat for example). When I try from terminal to send SIGSTOP to the child process, my_handler() gets called. But when I try to send SIGCONT to it, the the handler isn't called on macOS but it's executed on my Ubuntu. Man: SIGCHLD: child status has changed. Am I missing something? Is it an expected behaviour? I wrote my app on Ubuntu and expected it to work on mac as well. I tried with sigaction() as well, but with the same results. Here's a sample code to demonstrate:

What happens during this signal handling program?

一笑奈何 提交于 2019-12-02 03:54:32
问题 void main ( ) { int x; signal (SIGUSR1, f); x= fork ( ); if (x == -1) exit (1); if (x != 0) { kill (x, SIGUSR1) ; sleep (2); exit (0); } } void f ( ) { printf ("signal received"); exit (0); } I think that the program above asks the system to launch the f function ( which displays "signal received" ) when the SIGUSR1 signal is received by the parent process. but I'm not sure about that, please feel free to correct or to give more details. Thank for the help ! 回答1: There are some mistakes in

signal qt from a non-qt thread, QueuedConnection

五迷三道 提交于 2019-12-02 03:40:23
I am signaling my Qt GUI thread from a boost::thread, and I am using a Qt::QueuedConnection, connect(src, SIGNAL(signal-signature), dest, SLOT(slot-signature), Qt::QueuedConnection); and still, when I emit the signal my slot does not get called. edit: I found the problem, it seems that I was connecting the signal later then my call, but I was sure of the otherwise since breakpoints stopped first on the GUI thread at the connect call and then on the dispatch thread that does the emit ty everybody for the help and ideas :D Check whether the slot name and signal name are correct. Usually, if

order of SIGCONT and SIGHUP sent to orphaned linux process group

試著忘記壹切 提交于 2019-12-02 03:39:12
APUE says Since the process group is orphaned when the parentterminates, POSIX.1 requires that every process in the newly orphaned process group that is stopped (as our child is) be sent the hang-up signal (SIGHUP) followed by the continue signal (SIGCONT) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <errno.h> #define errexit(msg) do{ perror(msg); exit(EXIT_FAILURE); } while(0) static void sig_hup(int signo) { printf("SIGHUP received, pid = %d\n", getpid()); } static void sig_cont(int signo) { printf("SIGCONT received, pid = %d\n", getpid()); } static