signals

send signal from parent process to child in C

爱⌒轻易说出口 提交于 2019-12-09 03:51:28
问题 My child proccess can't start to work. I need to pass signal and execute readUsual function. This is a small piece of code: int main() { pid_t pid2 = fork(); if (pid2 < 0) printf("Can't create child process\n"); else if (pid2==0) { //this block never execute printf("Process2, pid=%d\n",getpid()); signal(SIGUSR1,readUsual); } else { kill(pid2,SIGUSR1); printf("%s\n","Proccess1 end"); for(;;); } return 0; } 回答1: You need to either add synchronization in some way, or call signal() before your

Handle connection/disconnection of many signals/slots with boost::signals2

霸气de小男生 提交于 2019-12-09 03:38:37
问题 I've started using boost::signals2 instead of my old signals-code. I'm having a problem with administering multiple connections though. Here's my problem: I have many instances of the class Person: class Person { public: void SetName (string new_name) { name = new_name; NameChange (name); } string name; boost::signals2::signal<Person*> NameChange; }; I also have a people-browser, that must monitor a subset of all available people for changes. Since people can come and go from that subset I

Catching signal inside its own handler

瘦欲@ 提交于 2019-12-09 02:38:10
问题 #include<stdio.h> #include<signal.h> void handler(int signo) { printf("Into handler\n"); while(1); } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(& act.sa_mask); sigaction(SIGINT, &act, NULL); while(1); return 0; } After catching the KeyboardInterrupt once, when I press "Ctrl+C" again, SIGINT is not handled... I intend that "Into handler" should be printed each time I press "Ctrl+C" . I want to catch SIGINT inside the "SIGINT handler()" itself..

Why use `sigsetjmp` instead of `setjmp` function in C? [closed]

ぐ巨炮叔叔 提交于 2019-12-08 18:11:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Why might somebody choose to use sigsetjmp instead of setjmp in C? I read in a book that there are some disadvantages in using setjmp with signal-related code, so the sigsetjmp function was implemented. Can anybody explain this with an example? Thanks in Advance. 回答1: See section 10.15 in “Advanced Programming

Is trap EXIT required to execute in case of SIGINT or SIGTERM received?

不打扰是莪最后的温柔 提交于 2019-12-08 17:36:53
问题 I have a simple script trap 'echo exit' EXIT while true; do sleep 1; done and it behaves differently in different shells: $ bash tst.sh ^Cexit $ dash tst.sh ^C $ zsh tst.sh ^C $ sh tst.sh ^Cexit So I'm not sure about how it should operate and whether it is specified at all. 回答1: The EXIT trap isn't working the same way in every shell. A few examples: In dash and zsh it's only triggered by a regular exit from within the script. In zsh, if you trap a signal that would normally quit the

What happens if during a signal handling in UNIX, the same signal gets sent to the program?

吃可爱长大的小学妹 提交于 2019-12-08 16:12:47
问题 Any ideas on this? Is there some kind of a signal queue, or does it get dropped? While we are at this question, is it true that signal handlers should do as minimal work as possible? I read somewhere that a signal handler should use a pipe and just write one byte to it, indicating what the program should do. Then somewhere else the program periodically checks the pipe, and dispatches based on byte in it. (I might have misunderstood it) Thanks, Boda Cydo. 回答1: To answer the second part of your

How to test signal handling in RSpec, particularly handling of SIGTERM?

别说谁变了你拦得住时间么 提交于 2019-12-08 16:03:17
问题 Heroku may send a SIGTERM to your application for various reasons, so I have created a handler to take care of some cleanup in case this happens. Some googling hasn't yielded any answers or examples on how to test this in RSpec. Here's the basic code: Signal.trap('TERM') do cleanup end def cleanup puts "doing some cleanup stuff" ... exit end What's the best way to test that this cleanup method is called when the program receives a SIGTERM? 回答1: Kill yourself! Send the signal to RSpec with

How long does it take for a non-blocked signal get delivered?

坚强是说给别人听的谎言 提交于 2019-12-08 15:56:10
问题 When one process sends a signal to another process, under what circumstances does receiving process wait until it is rescheduled to run? Under what circumstances does the installed signal handler get invoked immediately? How much overhead does the process incur when raising a signal compared to just call the corresponding signal handler directly? 回答1: About delivery of signals, TLPI states that signals are "normally" delivered when a task is next scheduled, when switching from kernel mode to

How to use SIGRTMIN in x86 or armeabi-v7a abi in Android NDK?

為{幸葍}努か 提交于 2019-12-08 14:28:11
问题 I am trying to use SIGRTMIN signal to create blocking signalhandler in Android NDK. int startThread(){ pthread_t thread; sigset_t set; /* Block SIGRTMIN other threads created by main() will inherit a copy of the signal mask. */ sigemptyset(&set); int rc = sigaddset(&set, SIGRTMIN); __android_log_print(ANDROID_LOG_DEBUG, "LOG", "Return Code:%d",rc); __android_log_print(ANDROID_LOG_DEBUG, "LOG", "Error Code:%d",errno); pthread_sigmask(SIG_BLOCK, &set, NULL); pthread_create(&thread, NULL, &sig

python SocketServer stuck on waitpid() syscall

爷,独闯天下 提交于 2019-12-08 13:34:58
问题 I am using Python (2.7) SocketServer with ForkingMixIn. It worked well. However sometimes on heavy usage (tons of rapidly connecting/disconnecting clients) the "server" stuck, consuming all the idle CPU (shown 100% CPU by top). If I use strace from CLI on the process it shows it does endless sequence of waitpid() syscall. According to command "ps" there are no child processes though at this point. After this problem my server implementation goes unusable and only its restarting helps :(