func mustSendSIGSEGV(){
    defer func() {
            if err := recover(); err != nil {
                fmt.Print("enter recover 111")
                // logger.PrintPanicStack()
            }
        }()
    var r *Test
    r.Num = 0
}
i rewrite mustSendSIGSEGV like this。it is same as before.. how to modify  
the default Go SIGSEGV handler?

在 2018年3月30日星期五 UTC+8上午12:42:42,Ian Lance Taylor写道:
>
> On Thu, Mar 29, 2018 at 8:48 AM, hexun via golang-nuts 
> <golan...@googlegroups.com <javascript:>> wrote: 
> >  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) 
> >     } 
> > } 
>
> Your SIGSEGV handler just returns, which means that the program 
> resumes execution at the point of failure.  In your mustSendSIGSEGV 
> function you haven't done anything to fix the code, so it just gets 
> another SIGSEGV. 
>
> Note that the default Go SIGSEGV handler does not simply return.  It 
> panics. 
>
> Ian 
>

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