signals

Why only async-safe functions should be called from a signal handler?

六月ゝ 毕业季﹏ 提交于 2019-11-29 17:08:32
I understand that, from a signal handler function sigaction() I should only call those functions that are "async-safe". But why is so? Calling an unsafe function may lead to undefined behavior. The Open Group Base Specifications Issue 7 (POSIX.1-2008), in its treatment of "Signal Concepts" , says: [W]hen a signal interrupts an unsafe function ... and the signal-catching function calls an unsafe function, the behavior is undefined. As to why unsafe functions are unsafe, there may be many reasons in a given implementation. However, a previous version of the standard, Issue 6 (POSIX.1-2004),

How to monitor an external process for events by its PID in C?

谁说我不能喝 提交于 2019-11-29 17:07:05
问题 Is there any library which's got some function the allows one to monitor an external process for events by its pid_t ? I mean, monitoring whether an external process has exited, or whether it has created one or more child processes (with fork ), or whether it has become another executable image (via an exec or posix_spawn function family call) or whether a Unix signal was delivered to it. EDIT I need something that does not interfere with the execution of the program that is being monitored.

what's the order of post_save receiver in django?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 16:52:53
You can bind multiple post_save(pre_save, etc) receivers to a class. Is there a way to specify the ordering of receipt of signals? Ordering signal in django would be a good feature but unfortunately Django does not support this as mentioned in this ticket although you can have a close look at Django Signals and the Observer Design Pattern to have better understanding of its pattern & design. 来源: https://stackoverflow.com/questions/20990146/whats-the-order-of-post-save-receiver-in-django

Using signals and sigpipe

我的梦境 提交于 2019-11-29 15:25:39
问题 I'm working on an assignment that involves writing a program to process data (calculate pi) using fork (processes), signals and select. I'm working right now on the signals and what I think I want to do is to use SIGPIPE so if the programs catches it, it tries to write to the pipe again (If a process tries to write to a pipe that has no reader, it will be sent the SIGPIPE). I use fork() in main() to assign each process the same work by sending them to the worker function. void worker(int id)

Linux C/C++ Timer signal handler in userspace

笑着哭i 提交于 2019-11-29 14:47:06
I need a function(eg signal handler) in C/C++ linux that gets activated every 'n' milliseconds. How do I setup signals etc...to register to timer events at the millisecond resolution. Accuracy is not super critical, but need within hundred ms or so. I am new to linux and I really don't know where to start. setitimer(2) is a good start, but do you really want to go asynchronous with signals? Otherwise, you could have a main loop with select(2) or poll(2) and an appropiate timeout. A much safer alternative to setitimer (which POSIX 2008 marks OBS olete) would be to use POSIX timers, and have the

Python - How to detect when user closes a console application via “X” button

China☆狼群 提交于 2019-11-29 14:28:28
I currently have a Console based python program running under windows. The program maintains most of its data in memory and periodically saves the data to disk, or when the user shuts the application down via a Keyboard interrupt ( Ctrl + C ) event. The problem i have is that when a user hits the "X" button at the top right of the console window, the session closes and the data in memory is lost. What i am looking for is an event/signal or hook so that i can clean up the memory before closing down. I am hoping to do this without any external libraries, though if this is not possible i'd still

After suspending child process with SIGTSTP, shell not responding

元气小坏坏 提交于 2019-11-29 13:53:49
I'm coding a basic shell in C, and I'm working on suspending a child process right now. I think my signal handler is correct, and my child process is suspending, but after that, the terminal should return to the parent process and that's not happening. The child is suspended, but my shell isn't registering any input or output anymore. tcsetpgrp() doesn't seem to be helping. Here's my signal handler in my shell code for SIGTSTP: void suspend(int sig) { pid_t pid; sigset_t mask; //mpid is the pgid of this shell. tcsetpgrp(STDIN_FILENO, mpid); tcsetpgrp(STDOUT_FILENO, mpid); sigemptyset(&mask);

Catch Windows terminal closing on running process

ぐ巨炮叔叔 提交于 2019-11-29 12:24:24
In a command prompt window, I have a running process. While the process is still executing, I click the (red) 'X' in the corner of the command prompt window. The command prompt window closes, and the running process is terminated. On Linux, closing the parent terminal of a running process will send that process SIGHUP . How do I catch this event on Windows? The equivalent of SIGHUP is provided through the callback you register with SetConsoleCtrlHandler . Your callback function will be called on an arbitrary threadpool thread with dwCtrlType = CTRL_CLOSE_EVENT. You've got 5 seconds to clean-up

MySQL: Unable to use SIGNAL in Trigger

陌路散爱 提交于 2019-11-29 11:58:22
I am trying to generate an error message using the MySQL trigger. Below is my code: DELIMITER $$ CREATE TRIGGER `test_before_insert` BEFORE INSERT ON `Initial_Fees` FOR EACH ROW BEGIN IF ((SELECT Activation from Portfolio WHERE idPortfolio = New.idPortfolio)=false) THEN SIGNAL SQLSTATE '45000'; SET MESSAGE_TEXT := 'Disabled Thing'; END IF; END$$ DELIMITER ; But this always generates an error. I don't know what the error is, because It is not saying anything about the error, it is just "Error". Any advice on this please? Apart from that, some people say using SIGNAL is subjected to issues

Windows console application - signal for closing event

て烟熏妆下的殇ゞ 提交于 2019-11-29 11:54:49
In windows console application, one can catch pressing ctrl+c by using: #include <stdio.h> #include <signal.h> void SigInt_Handler(int n_signal) { printf("interrupted\n"); } int main(int n_arg_num, const char **p_arg_list) { signal(SIGINT, &SigInt_Handler); getchar(); // wait for user intervention } This works well, except it does not work at all if the user presses the cross × that closes the console window. Is there any signal for that? The reason I need this is I have this CUDA application which tends to crash the computer if closed while computing something. The code is kind of