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 by zero" exception?
public class Main {
public static void main(String[] args) {
int a = 2;
int b = 0;
System.out.println(a / b);
}
}
strace java -Xcomp Main
... ...
mprotect(0xf6949000, 8171520, PROT_READ|PROT_WRITE) = 0
mprotect(0xf6949000, 8171520, PROT_READ|PROT_EXEC) = 0
munmap(0xf774f000, 5727) = 0
mmap2(NULL, 331776, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0xfffffffff68d0000
mprotect(0xf68d0000, 4096, PROT_NONE) = 0
clone(child_stack=0xf6920494, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0xf6920bd8, tls=0xf6920bd8, child_tidptr=0xff9c5520) = 958
futex(0xf6920bd8, FUTEX_WAIT, 958, NULL) = 0
exit_group(0)