forked from openshift/openshift-state-metrics
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move reaper from origin to here as it was deleted in source repository
- Loading branch information
1 parent
af0172e
commit 80f049b
Showing
3 changed files
with
46 additions
and
1 deletion.
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
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,37 @@ | ||
// +build linux | ||
|
||
package proc | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
// StartReaper starts a goroutine to reap processes if called from a process | ||
// that has pid 1. | ||
func StartReaper() { | ||
if os.Getpid() == 1 { | ||
klog.V(4).Infof("Launching reaper") | ||
go func() { | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGCHLD) | ||
for { | ||
// Wait for a child to terminate | ||
sig := <-sigs | ||
klog.V(4).Infof("Signal received: %v", sig) | ||
for { | ||
// Reap processes | ||
cpid, _ := syscall.Wait4(-1, nil, syscall.WNOHANG, nil) | ||
if cpid < 1 { | ||
break | ||
} | ||
|
||
klog.V(4).Infof("Reaped process with pid %d", cpid) | ||
} | ||
} | ||
}() | ||
} | ||
} |
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,8 @@ | ||
// +build !linux | ||
|
||
package proc | ||
|
||
// StartReaper has no effect on non-linux platforms. | ||
// Support for other unices will be added. | ||
func StartReaper() { | ||
} |