[英]Why mustSendSIGSEGV() will continue print, but syscall.Kill(pid, syscall.SIGSEGV) only print once
誰能告訴我為什么syscall.Kill(pid, syscall.SIGSEGV)
只打印"handlerSIGSEGV Sent by 0"
一次,但mustSendSIGSEGV會無限打印"handlerSIGSEGV Sent by 0"
。
我想要golang SIGSEGV傳遞給C,只處理一次,而不是多次。 誰能幫我?
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)
}
}
從“ Go編程語言”中,我看到了這一點:
如果非Go代碼為任何同步信號(SIGBUS,SIGFPE,SIGSEGV)安裝了信號處理程序,則它應記錄現有的Go信號處理程序。 如果在執行Go代碼時發生這些信號,則應調用Go信號處理程序(可以通過查看傳遞給信號處理程序的PC來確定在執行Go代碼時是否發生信號)。 否則,某些Go運行時恐慌將不會按預期發生。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.