This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
627a3ac
commit 6b7940a
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
} | ||
if err == syscall.ECHILD { | ||
break | ||
} | ||
log.Printf("pid %d, finished, wstatus: %+v", pid, wstatus) | ||
} | ||
} |
1 comment
on commit 6b7940a
There was a problem hiding this comment.
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
the inner for-loop is semantically same as this?