signals

Pass arguments to signal handler in C

痴心易碎 提交于 2019-12-10 23:35:11
问题 How can I pass arguments (e.g. a pointer to a struct) to a signal handler? I'm writing a multithread application, so I cannot use global variables I associate a timer to each thread. When timer expires I have to update a struct (each thread has a different struct). How can I do? 回答1: The way the signal handler is called by the system is fixed -- there's no way to change it and add an additional user pointer. So if you want to get additional data into the signal handler, the only way to do it

Signal handler question

牧云@^-^@ 提交于 2019-12-10 21:43:47
问题 We've been covering signals in C/Unix, and the professor gave an example in class that is confusing me. In the main method below, the signal function is called with the included arguments. main() { signal(SIGALRM, handler); // install handler handler is a function defined as static void handler(int param){ According to the Ubuntu man 7 signal , SIGALRM is an integer value 14, and handler is a programmer defined function. However, the integer parameter is not explicitly defined in the signal

“kill -15” triggers the sigaction code but does not terminate my C program

拥有回忆 提交于 2019-12-10 21:35:04
问题 I have a program developed in C. I added to this program a sigaction handler inorder to execute some C code before quit the program: void signal_term_handler(int sig) { printf("EXIT :TERM signal Received!\n"); int rc = flock(pid_file, LOCK_UN | LOCK_NB); if(rc) { char *piderr = "PID file unlock failed!"; fprintf(stderr, "%s\n", piderr); printf(piderr); } exit(EXIT_SUCCESS); } int main(int argc, char **argv) { struct sigaction sigint_action; sigint_action.sa_handler = &signal_term_handler;

Why does my bash script take so long to respond to kill when it runs in the background?

拈花ヽ惹草 提交于 2019-12-10 21:08:13
问题 (Question revised, now that I understand more about what's actually happening) : I have a script that runs in the background, periodically doing some work and then sleeping for 30 seconds: echo "background script PID: $$" trap 'echo "Exiting..."' INT EXIT while true; do # check for stuff to do, do it sleep 30 done & If I try to kill this script via kill or kill INT , it takes 30 seconds to respond to the signal. I will answer this question below, since I found a good explanation online. ( My

Signal Handler to stop Timer in C

狂风中的少年 提交于 2019-12-10 20:22:26
问题 I am trying to have a signal handler stop a timer without exiting my program. How should I go about. I want StopTimer to handle the signal to stop the timer #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <sys/time.h> #include <signal.h> #include <unistd.h> #define INTERVAL 2 // number of seconds to go off int main(int argc, char* argv[]) { TimerSet(INTERVAL); while(1) { // do stuff } return 0; } void TimerSet(int interval) { printf("starting timer\n"); struct itimerval

How can I handle Ctrl+C in a Windows CE console application?

不羁的心 提交于 2019-12-10 20:13:49
问题 I need to make some clean up before closing my application, but SetConsoleCtrlHandler doesn't seem to be available for Windows CE console applications. Is there any alternative method for handling Ctrl+C in Windows CE 6? 回答1: According to Microsoft's documentation, on Windows CE 3.0 and up, the DeviceIoControl function called with the IOCTL_CONSOLE_SETCONTROLCHANDLER control code will install a Ctrl+C handler on Windows CE. I haven't tried it out myself yet, but something like this "should"

Return value of signal

梦想的初衷 提交于 2019-12-10 19:47:25
问题 I was reading about the signal function, the definition is: void (*signal(int sig, void (*func)(int)))(int); and the return value is: If the request can be honored, signal() shall return the value of func for the most recent call to signal() for the specified signal sig. Otherwise, SIG_ERR shall be returned and a positive value shall be stored in errno. The doubt is: isn't signal a void function? Should it return nothing? 回答1: The actual signal handler function is a function with void return.

Detect when column in gtk.treeview is resized

自作多情 提交于 2019-12-10 18:56:45
问题 What signal can I catch to detect when a column changes size in a gtk.TreeView ? I can't seem to find it in the docs. 回答1: gtk.TreeViewColumns aren't widgets so they unfortunately don't have a dedicated signal for size changes. But you can register a callback function that receives "width" change notifications: def onColWidthChange(col, width): # Note that "width" is a GParamInt object, not an integer ... col.connect("notify::width", onColWidthChange) In the example, col must be a gtk

perl - child process signaling parent

亡梦爱人 提交于 2019-12-10 18:54:59
问题 I have written the following piece of code to test signaling between child and parent. Ideally, when the child gives a SIGINT to parent the parent should come back in the new iteration and wait for user input. This I have observed in perl 5.8, but in perl 5.6.1(which I am asked to use) the parent is actually "killed". There is no next iteration. my $parent_pid = $$; $pid = fork(); if($pid == 0) { print "child started\n"; kill 2, $parent_pid; } else { while(1) { eval { $SIG{INT} = sub{die

Is there a way to listen to signals on Windows

妖精的绣舞 提交于 2019-12-10 18:27:58
问题 I'm writing a small shell for Windows in Rust, and want to kill the Command I spawned and prevent my shell from quitting. Is there a way of capturing the Windows SIGINT equivalent in Rust? 回答1: There is a crate, chan-signal , that aims to help in handling this, by spawning a thread and having it wait for signals. EDIT: It doesn't currently support windows. There is an RFC asking for this functionality to be integrated into the language's standard library, but it is very young. It seems your