mirror of https://github.com/gofiber/fiber.git
👪 Combine helper fn's in prefork.go
Co-Authored-By: RW <renewerner87@googlemail.com> Co-Authored-By: kiyon <kiyonlin@users.noreply.github.com>pull/662/head
parent
81873905f9
commit
e4b345b35c
30
prefork.go
30
prefork.go
|
@ -120,3 +120,33 @@ func (app *App) prefork(addr string, tlsconfig ...*tls.Config) (err error) {
|
|||
// return error if child crashes
|
||||
return (<-channel).err
|
||||
}
|
||||
|
||||
// watchMaster watches child procs
|
||||
func watchMaster() {
|
||||
if runtime.GOOS == "windows" {
|
||||
// finds parent process,
|
||||
// and waits for it to exit
|
||||
p, err := os.FindProcess(os.Getppid())
|
||||
if err == nil {
|
||||
_, _ = p.Wait()
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
// if it is equal to 1 (init process ID),
|
||||
// it indicates that the master process has exited
|
||||
for range time.NewTicker(time.Millisecond * 500).C {
|
||||
if os.Getppid() == 1 {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dummyChildCmd = "go"
|
||||
|
||||
// dummyCmd is for internal prefork testing
|
||||
func dummyCmd() *exec.Cmd {
|
||||
if runtime.GOOS == "windows" {
|
||||
return exec.Command("cmd", "/C", dummyChildCmd, "version")
|
||||
}
|
||||
return exec.Command(dummyChildCmd, "version")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue