Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
fix #26
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jul 11, 2017
1 parent 627a3ac commit 6b7940a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sigchld_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// +build linux darwin

package main

import (
"syscall"

"github.com/qiniu/log"
)

func init() {
go reapChildren()
}

func reapChildren() {
var wstatus syscall.WaitStatus

for {
pid, err := syscall.Wait4(-1, &wstatus, 0, nil)
for err == syscall.EINTR {
pid, err = syscall.Wait4(-1, &wstatus, 0, nil)

This comment has been minimized.

Copy link
@c0b

c0b Jul 11, 2017

Contributor

the inner for-loop is semantically same as this?

if err == syscall.EINTR {
	continue
}
}
if err == syscall.ECHILD {
break
}
log.Printf("pid %d, finished, wstatus: %+v", pid, wstatus)
}
}

1 comment on commit 6b7940a

@c0b
Copy link
Contributor

@c0b c0b commented on 6b7940a Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be full-featured, the yelp engineering's dumb-init is a better reference:

https://github.com/Yelp/dumb-init/blob/master/dumb-init.c#L90-L118

the behavior is to reap when SIGCHLD happens, or forward the signal if not SIGCHLD; details well described in their engineering blog:
https://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html

Please sign in to comment.