시그널

김새우·2022년 9월 20일
0

go

목록 보기
4/13

unix 시그널 처리 방안이 필요

sigterm signal을 받았을 때 적절하게 서버를 종료해주는 등
커맨드 라인에서 sigint를 받았을때 등등

func  main(){

	fmt.Printf("pid :  %d\n", os.Getpid())

	sigs := make(chan os.Signal, 1)
	done := make(chan bool, 1)

	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		sig := <-sigs
		fmt.Println()
		fmt.Println(sig)
		done <- true
	}()

	fmt.Println("awaiting signal")
	<-done
	fmt.Println("exiting")


}

1. SIGHUP: 연결된 terminal이 hangup 하였을 때(terminate)
2. SIGINT: interrupt key(^C)를 입력하였을 때(terminate)
3. SIGQUIT: quit key(^)를 입력하였을 때(terminate+core)
4. SIGILL: illegal instruction을 수행하였을 때(terminate+core)
5. SIGTRAP: implementation defined hardware fault (terminate+core)
6. SIGABRT: abort 시스템 호출을 불렀을 때(terminate+core)
7. SIGBUS: implementation defined hardware fault (terminate+core)
8. SIGFPE: arithmetic exception, /0, floating-point overflow (terminate+core)
9. SIGKILL: process를 kill 하기 위해 signal, catch 혹은 ignore될 수 없는 signal임(terminate)
10. SIGUSR1: user defined signal 1 (terminate)
11. SIGSEGV: invalid memory reference (terminate+core)
12. SIGUSR2: user defined signal 2 (terminate)
13. SIGPIPE: reader가 terminate된 pipe에 write할 경우 발생(terminate)
14. SIGALRM: alarm 시스템 호출 후 timer가 expire된 경우(terminate)
15. SIGTERM: kill 시스템 호출이 보내는 software termination signal (terminate)
16. SIGCHLD: child가 stop or exit되었을 때 parent에게 전달 되는 신호(ignore)
17. SIGCONT: continue a stopped process (continue/ignore)
18. SIGSTOP: sendable stop signal, cannot be caught or ignored (stop process)
19. SIGTSTP: stop key(^Z)를 입력하였을 때(stop process)
20. SIGTTIN: background process가 control tty로부터 read 할 경우(stop process)
21. SIGTTOU: background process가 control tty로 write 할 경우(stop process)
22. SIGURG: urgent condition on IO, socket의 OOB data (ignore)
23. SIGXCPU: exceeded CPU time limit (terminate+core/ignore)
24. SIGXFSZ: exceeded file size limit (terminate+core/ignore)
25. SIGVTALRM: virtual time alarm, setitimer, (terminate)
26. SIGPROF: profiling time alarm, setitimer, (terminate)
27. SIGWINCH: terminal window size changed, (ignore)
28. SIGIO: 어떤 fd에서 asynchronous I/O event가 발생하였을 경우(terminate/ignore)
29. SIGPWR: system power fail (terminate/ignore)
30. SIGSYS: bad argument to system call (terminate+core)

0개의 댓글