initial import
This commit is contained in:
42
core/proc/signals.go
Normal file
42
core/proc/signals.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// +build linux darwin
|
||||
|
||||
package proc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"zero/core/logx"
|
||||
)
|
||||
|
||||
const timeFormat = "0102150405"
|
||||
|
||||
func init() {
|
||||
go func() {
|
||||
var profiler Stopper
|
||||
|
||||
// https://golang.org/pkg/os/signal/#Notify
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM)
|
||||
|
||||
for {
|
||||
v := <-signals
|
||||
switch v {
|
||||
case syscall.SIGUSR1:
|
||||
dumpGoroutines()
|
||||
case syscall.SIGUSR2:
|
||||
if profiler == nil {
|
||||
profiler = StartProfile()
|
||||
} else {
|
||||
profiler.Stop()
|
||||
profiler = nil
|
||||
}
|
||||
case syscall.SIGTERM:
|
||||
gracefulStop(signals)
|
||||
default:
|
||||
logx.Error("Got unregistered signal:", v)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user