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)
}
}