signals

In java, “5/0” statement doesn't fire SIGFPE signal on my Linux machine, why?

我们两清 提交于 2019-12-01 17:30:01
I wrote a very simple c program: #include<stdio.h> int main(){ int a=2; int b=0; printf("%d\n", a/b); } and run it with strace: strace ./a.out and get below output (only paste tail part) ... ... mprotect(0x600000, 4096, PROT_READ) = 0 mprotect(0x7f04c7fb8000, 4096, PROT_READ) = 0 munmap(0x7f04c7f96000, 127640) = 0 --- SIGFPE (Floating point exception) @ 0 (0) --- +++ killed by SIGFPE +++ Floating point exception The output matches my expectation, as it was killed by SIGFPE signal. However, the same program written in Java, doesn't get SIGFPE signal, does anybody know how java processes "divide

how to find wifi signal direction of another device in android?

China☆狼群 提交于 2019-12-01 17:29:02
I am using my android phone as Access Point. Now I want to find the distance and direction of the wifi devices connected with my phone. Please help me through suitable example and code. Thanks in advance. I downloaded Wifi Radar that you mentioned and tried it. There's an important step there - it asks you to rotate on the spot for a bit while holding the device to your body. So my guess is that it uses the internal compass to figure out which direction you're pointing to, and then measures the signal. When the signal gets stronger, it figures that you're pointing toward the AP. Since the app

Why only async-signal-safe functions can be called from signal handlers safely?

萝らか妹 提交于 2019-12-01 17:22:13
I am still a little confused as to why exactly it is unsafe to receive a signal and call a non async safe function from within that signal handler. Could someone explain the reasoning behind this and possibly try and give me some references that I can follow to read up more on this myself? In other words I am asking why it is unsafe to say call printf from within a signal handler. Is it because of intra-process issues and possible race conditions resulting from two possible calls to printf without protection or is it because of inter process races to the same resource (in this example stdout).

How to make a function async-signal-safe?

南笙酒味 提交于 2019-12-01 17:14:53
问题 I have the following sigaction handler function 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); } abort(); } Someone told me that flock and printf aren't async-signal-safe. And I could not find an alternate async-signal-safe function for flock in this list. and according to the above link: when a signal interrupts an

python timer mystery

大憨熊 提交于 2019-12-01 16:58:42
Well, at least a mystery to me. Consider the following: import time import signal def catcher(signum, _): print "beat!" signal.signal(signal.SIGALRM, catcher) signal.setitimer(signal.ITIMER_REAL, 2, 2) while True: time.sleep(5) Works as expected i.e. delivers a "beat!" message every 2 seconds. Next, no output is produced: import time import signal def catcher(signum, _): print "beat!" signal.signal(signal.SIGVTALRM, catcher) signal.setitimer(signal.ITIMER_VIRTUAL, 2, 2) while True: time.sleep(5) Where is the issue? From my system's man setitimer (emphasis mine): The system provides each

In java, “5/0” statement doesn't fire SIGFPE signal on my Linux machine, why?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 16:27:13
问题 I wrote a very simple c program: #include<stdio.h> int main(){ int a=2; int b=0; printf("%d\n", a/b); } and run it with strace: strace ./a.out and get below output (only paste tail part) ... ... mprotect(0x600000, 4096, PROT_READ) = 0 mprotect(0x7f04c7fb8000, 4096, PROT_READ) = 0 munmap(0x7f04c7f96000, 127640) = 0 --- SIGFPE (Floating point exception) @ 0 (0) --- +++ killed by SIGFPE +++ Floating point exception The output matches my expectation, as it was killed by SIGFPE signal. However,

Floating Point Exception Core Dump

倖福魔咒の 提交于 2019-12-01 16:17:16
I am newbie on the Linux signals, please help. The following code get core dump when run in Linux 2.6 gcc. $ ./a.out Floating point exception (core dumped) The questions: 1. Since a process signal mask is installed, shouldn't the "SIGFPGE" generated by line 40 volatile int z = x/y; be blocked? 2. If it is not blocked, since a signal handler has been installed, shouldn't the "SIGFPE" be captured by the signal handler, instead of a core dump? 3. If I commented out line 40 volatile int z = x/y; , and use line 42 raise(SIGFPE); instead, then everything works as I expected. What is the difference

How should I close a socket in a signal handler?

醉酒当歌 提交于 2019-12-01 16:13:05
I'm writing a very simple server that loops forever until Ctrl-C is pressed. I'd like to have the signal handler for ctrl-c close the open sockets and shut down the server, but I don't know what the scope is for a signal handler, and I don't like the idea of declaring the socket(s) I would need to close to be global. Can someone offer suggestions? Is there some standard way to do this? Well, since you have signal handlers, I'm going to assume you're on a Unix variant. If so: A socket is identified to the kernel by the file number, which is an int. See socket(2) . That int is valid for your

How should I close a socket in a signal handler?

旧城冷巷雨未停 提交于 2019-12-01 15:52:14
问题 I'm writing a very simple server that loops forever until Ctrl-C is pressed. I'd like to have the signal handler for ctrl-c close the open sockets and shut down the server, but I don't know what the scope is for a signal handler, and I don't like the idea of declaring the socket(s) I would need to close to be global. Can someone offer suggestions? Is there some standard way to do this? 回答1: Well, since you have signal handlers, I'm going to assume you're on a Unix variant. If so: A socket is

Is it possible to ignore all signals?

社会主义新天地 提交于 2019-12-01 15:23:28
I have a server application which I want to protect from being stopped by any signal which I can ignore. Is there a way to ignore all possible signals at once, without setting them one by one? Yes: #include <signal.h> sigset_t mask; sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); This does not exactly ignore the signals, but blocks them; which in practice is the same effect. I guess there's no need to mention that SIGKILL and SIGSTOP cannot be blocked nor ignored in any way. For more detailed semantics, like mask inheritance rules and the like, check the man page Blocking signals is