From "The Go Programming Language" I see this:

If the non-Go code installs any signal handlers, it must use the SA_ONSTACK 
flag with sigaction. Failing to do so is likely to cause the program to 
crash if the signal is received.



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\n", 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)
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to