signals

How to handle the signal in python on windows machine

廉价感情. 提交于 2019-11-26 20:34:44
问题 I am trying the code pasted below on Windows, but instead of handling signal, it is killing the process. However, the same code is working in Ubuntu. import os, sys import time import signal def func(signum, frame): print 'You raised a SigInt! Signal handler called with signal', signum signal.signal(signal.SIGINT, func) while True: print "Running...",os.getpid() time.sleep(2) os.kill(os.getpid(),signal.SIGINT) 回答1: Python's os.kill wraps two unrelated APIs on Windows. It calls

Alternative to sun.misc.Signal

狂风中的少年 提交于 2019-11-26 20:20:13
问题 I started research to find an alternative to the sun.misc.Signal class, because it could be unsupported in upcoming JDKs (we're currently working on 1.6). When I build the project I get: warning: sun.misc.SignalHandler is Sun proprietary API and may be removed in a future release I came across multiple solutions but they don't fit my project e.g. in this question. This is unacceptable in my situation because: Signals are used not only for killing application The application is huge - every

SIGKILL signal Handler

谁说我不能喝 提交于 2019-11-26 20:15:17
问题 I have a requirement to write to a log file on reception of any terminate command like SIGTERM AND SIGKILL. I can register for SIGTERM but how can handle the SIGKILL signal? 回答1: You cannot, at least not for the process being killed. What you can do is arrange for the parent process to watch for the child process's death, and act accordingly. Any decent process supervision system, such as daemontools, has such a facility built in. 来源: https://stackoverflow.com/questions/3908694/sigkill-signal

Signal handling with multiple threads in Linux

佐手、 提交于 2019-11-26 19:22:18
In Linux, what happens when a program (that possibly has multiple threads) receives a signal, like SIGTERM or SIGHUP? Which thread intercepts the signal? Can multiple threads get the same signal? Is there a special thread dedicated entirely to handling signals? If not, what happens inside the thread that is to handle the signal? How does the execution resume after the signal handler routine finishes? This is slightly nuanced, based on which version of the Linux kernel you are using. Assuming 2.6 posix threads, and if you are talking about the OS sending SIGTERM or SIGHUP, the signal is sent to

What's the difference between SIGSTOP and SIGTSTP?

一笑奈何 提交于 2019-11-26 18:53:08
问题 That's it. Just wondering about the difference between SIGSTOP and SIGTSTP. 回答1: Both signals are designed to suspend a process which will be eventually resumed with SIGCONT . The main differences between them are: SIGSTOP is a signal sent programmatically (eg: kill -STOP pid ) while SIGTSTP (for sig nal - t erminal stop ) may also be sent through the tty driver by a user typing on a keyboard, usually Control - Z . SIGSTOP cannot be ignored. SIGTSTP might be. 回答2: /usr/include/x86_64-linux

What does fflush(stdin) do in C programing? [duplicate]

自作多情 提交于 2019-11-26 18:50:49
This question already has an answer here: Using fflush(stdin) 4 answers I am very new to C programming and I am trying to understand how fflush(stdin) really works. In the following example does fflush(stdin) clears all the buffer or it clears whatever entered after the third item? What I mean is user enters account number, space, name, space, balance. Is that true that from this point on, whatever the user enters will be flushed with fflush(stdin) ? and stdin won't be empty. Why do I say that is because it enters into a while loop and starts writing to the text file. My second question is

How to handle a ctrl-break signal in a command line interface

妖精的绣舞 提交于 2019-11-26 18:26:58
问题 Before I begin, I want to clarify that this is not a command-line tool, but an application that accepts commands through it's own command-line interface. Edit: I must apologize about my explanation from before, apparently I didn't do a very good job at explaining it. One more time... I am building a command-line interface application that accepts commands from a user. I have a signal handler setup to catch the signals, which then sets a flag that I need to terminate the application. The

Longjmp out of signal handler?

爱⌒轻易说出口 提交于 2019-11-26 18:21:57
问题 From the question: Is it good programming practice to use setjmp and longjmp in C? Two of the comments left said: "You can't throw an exception in a signal handler, but you can do a longjmp safely -- as long as you know what you are doing. – Dietrich Epp Aug 31 at 19:57 @Dietrich: +1 to your comment. This is a little-known and completely-under-appreciated fact. There are a number of problems that cannot be solved (nasty race conditions) without using longjmp out of signal handlers.

Signals received by bash when terminal is closed

送分小仙女□ 提交于 2019-11-26 17:45:00
问题 Use trap to capture signals like this: i=-1;while((++i<33)); do trap "echo $i >> log.txt" $i; done And close the terminal by force. The content in log.txt is then (under redhat linux): 1 18 1 17 0 Where these signals from? 回答1: The first signal is SIGHUP; that gets sent to all processes in the process group when the terminal disconnects (hangs up - hence HUP). The second signal is SIGCONT (thanks, SiegeX, for the numbers). This is slightly surprising; it suggests you had a job stopped in the

How to suspend/resume a process in Windows?

六月ゝ 毕业季﹏ 提交于 2019-11-26 17:18:29
In Unix we can suspend a process execution temporarily and resume it with signals SIGSTOP and SIGCONT . How can I suspend a single-threaded process in Windows without programming ? You can't do it from the command line, you have to write some code (I assume you're not just looking for an utility otherwise Super User may be a better place to ask). I also assume your application has all the required permissions to do it (examples are without any error checking). Hard Way First get all the threads of a given process then call the SuspendThread function to stop each one (and ResumeThread to resume