signals

What happens during this signal handling program?

穿精又带淫゛_ 提交于 2019-12-02 02:16:31
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 ! Grijesh Chauhan There are some mistakes in your code: Avoid calling printf( ) function in signal handler. SIGNAL(7) manual provides a

Handling Signals in an MPI Application / Gracefully exit

久未见 提交于 2019-12-02 01:16:10
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 MPI_FINALIZE() ? Somehow the processes have to aggree on exiting (I think this is the same in

Signal (SIGTERM) not received by subprocess on Windows

时间秒杀一切 提交于 2019-12-02 00:48:34
I have a server that starts a subprocess, and I can manage to do a send_signal(SIGTERM) which will kill the process. But not gracefully. If I call my subprocess from shell (i.e. as a single process), the defined signal handler will kick in and exit gracefully. server.py: (so.. from another script I first call start_app() , and later exit_app() def start_app(): app = subprocess.Popen("python app.py") def exit_app(): p = app.poll() if p==None: print("Subprocess is alive") # debug app.send_signal(signal.SIGTERM) app.py def exit_signal_handler(signal, frame): print("Terminate signal received") app

Signal (SIGTERM) not received by subprocess on Windows

丶灬走出姿态 提交于 2019-12-02 00:18:20
问题 I have a server that starts a subprocess, and I can manage to do a send_signal(SIGTERM) which will kill the process. But not gracefully. If I call my subprocess from shell (i.e. as a single process), the defined signal handler will kick in and exit gracefully. server.py: (so.. from another script I first call start_app() , and later exit_app() def start_app(): app = subprocess.Popen("python app.py") def exit_app(): p = app.poll() if p==None: print("Subprocess is alive") # debug app.send

Second signal call in sighandler - what for?

不打扰是莪最后的温柔 提交于 2019-12-02 00:15:52
Recently I found some code which uses signal : 286 static void sighandler( int signum ) 287 { 288 alarmed = 1; 289 signal( signum, sighandler ); 290 } 291 292 void set_alarm( int seconds ) 293 { 294 alarmed = 0; 295 signal( SIGALRM, sighandler ); 296 alarm( seconds ); 297 } I have some troubles to figure out why do I need to call signal 2 times, especially, why do I need to call signal in sighandler ? I know what the above code does but dont understand why do I need to call signal 2 times. Handling Signals The call to signal establishes signal handling for only one occurrence of a signal.

How to get a reference to an instance method from a decorator

风格不统一 提交于 2019-12-02 00:07:39
I have been using a GUI library that allows you to connect signals to signal handlers using a connect function, for example: widget.connect(signal, callback) Means that the function callback will be run whenever the signal is fired from the widget. In an attempt to make my code nicer, and remove a series of connect calls from my constructor, I decided to use a decorator, which works well: def callback(widget, signal) def decorate(f): widget.connect(signal, f) return f return decorate ... @callback(widget, signal) def do_something(): ... This works excellently until I needed to do this in a

How to get a reference to an instance method from a decorator

那年仲夏 提交于 2019-12-01 23:47:50
问题 I have been using a GUI library that allows you to connect signals to signal handlers using a connect function, for example: widget.connect(signal, callback) Means that the function callback will be run whenever the signal is fired from the widget. In an attempt to make my code nicer, and remove a series of connect calls from my constructor, I decided to use a decorator, which works well: def callback(widget, signal) def decorate(f): widget.connect(signal, f) return f return decorate ...

Boost::signals2 - descruction of an object with the slot

南楼画角 提交于 2019-12-01 23:39:49
Consider this: #include <boost/signals2.hpp> #include <iostream> struct object_with_slot { void operator()() { std::cout << "Slot called!" << std::endl; member = 50500; } int member; }; int main() { boost::signals2::signal<void ()> sig; object_with_slot * ptr = new object_with_slot; sig.connect(*ptr); delete ptr; sig(); } Output is "Slot called!" and no crash or anything. That's why I have a few questions: 1) Why there is no crash? 2) Why there is no crash even if the slot function assigns something to object which doesn't exist? 3) How can I make the signal automatically track the lifetime of

Why doesn't Linux accept() return EINTR?

陌路散爱 提交于 2019-12-01 21:31:28
Environment: a RedHat-like distro, 2.6.39 kernel, glibc 2.12. I fully expect that if a signal was delivered while accept() was in progress, accept should fail, leaving errno==EINTR. However, mine doesn't do that, and I'm wondering why. Below are the sample program, and strace output. #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <signal.h> #include <errno.h> #include <arpa/inet.h> #include <string.h> static void sigh(int); int main(int argc, char ** argv) { int s; struct sockaddr_in sin; if ((s = socket(AF_INET, SOCK_STREAM, 0))<0) { perror("socket"); return 1; }

PHP PCNTL - what does pcntl_signal()'s restart_syscalls parameter do?

让人想犯罪 __ 提交于 2019-12-01 17:54:28
问题 I've been using PHP's PCNTL extension for a little while now, but can't figure out what the restart_syscalls parameter of pcntl_signal() does. I tried looking around the Internets, but couldn't find any information. All the documentation says is: "Specifies whether system call restarting should be used when this signal arrives." What is "system call restarting"? 回答1: Suppose you programmed your signal handler to stop a process using signals like: SIGTERM : to terminate a process; it can be