-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not functional on Docker Alpine #38
Comments
@Juriy this is what I was able to whip up in my own project: export const killChildren = (pid: number) => {
const children = [];
try {
const psRes = execSync(`ps -opid="" -oppid="" |grep ${pid}`).toString().trim().split(/\n/);
(psRes || []).forEach(pidGroup => {
const [actual, parent] = pidGroup.trim().split(/ +/);
if (parent.toString() === pid.toString()) {
children.push(parseInt(actual, 10));
}
});
} catch (e) {}
try {
kill(pid);
children.forEach(childPid => kill(childPid));
} catch (e) {}
}; |
thanks @m0ngr31 for that code sample. I ended up stealing it and using it in my project (WTFPL). Hope you don't mind me adapting it into my library and re-licensing as such? |
Go for it |
Hello,
Trying to use this module for killing a process tree in Docker that is built on Alpine image. Unfortunately, the module fails to create a process tree, since
ps
does not support some of the flags that the module is relying on: --no-headers and --ppid. This results in a process returning non-zero code. Module interprets non-zero as "no child processes" and swallows the error silently.I was trying to find a way to change the command in
buildProcessTree
so that it simulates the same output. Removing header is easy - we can pass the names of the columns with -o, removing the header completely:But lack of --ppid filter support making it slightly more challenging. My Linux knowledge is not enough to tell if manually filtering by ppid in the following command would do the trick:
If that's the case, it would probably be the most portable version (except for the cases when
ps
is not present at all as described in #36If there's an ambition to rewrite this part of the code, I am happy to collaborate 🙂
The text was updated successfully, but these errors were encountered: