Can any one tell me why syscall.Kill(pid, syscall.SIGSEGV)
only print "handlerSIGSEGV Sent by 0"
once ,but mustSendSIGSEGV will print "handlerSIGSEGV Sent by 0"
Unlimited times。
I want golang SIGSEGV pass to C, only handle once, not many times. Can anyone help me?
package main
/*
#include <stdio.h>
#include <signal.h>
#include <string.h>
struct sigaction old_action;
void handlerSIGSEGV(int signum, siginfo_t *info, void *context) {
printf("handlerSIGSEGV Sent by %d
", info->si_pid);
}
void testSIGSEGV() {
struct sigaction action;
sigaction(SIGSEGV, NULL, &action);
memset(&action, 0, sizeof action);
sigfillset(&action.sa_mask);
action.sa_sigaction = handlerSIGSEGV;
action.sa_flags = SA_NOCLDSTOP | SA_SIGINFO | SA_ONSTACK;
sigaction(SIGSEGV, &action, &old_action);
}
*/
import "C"
import (
"os"
"syscall"
"time"
"fmt"
)
type Test struct {
Num int
}
func mustSendSIGSEGV(){
var r *Test
r.Num = 0
}
func main() {
// C.test()
C.testSIGSEGV()
pid := os.Getpid()
syscall.Kill(pid, syscall.SIGSEGV)
// mustSendSIGSEGV()
for {
// syscall.Kill(pid, syscall.SIGUSR1)
fmt.Print("33")
time.Sleep(time.Second)
}
}
From "The Go Programming Language" I see this:
If the non-Go code installs a signal handler for any of the synchronous signals (SIGBUS, SIGFPE, SIGSEGV), then it should record the existing Go signal handler. If those signals occur while executing Go code, it should invoke the Go signal handler (whether the signal occurs while executing Go code can be determined by looking at the PC passed to the signal handler). Otherwise some Go run-time panics will not occur as expected.