我正在尝试在linux中尝试使用openssl speed
来刻录cpu这是来自netflix simian army的代码
#!/bin/bash
# Script for BurnCpu Chaos Monkey
cat << EOF > /tmp/infiniteburn.sh
#!/bin/bash
while true;
do openssl speed;
done
EOF
# 32 parallel 100% CPU tasks should hit even the biggest EC2 instances
for i in {1..32}
do
nohup /bin/bash /tmp/infiniteburn.sh &
done
所以这是Netflix simian军队代码做烧cpu,这个执行得不错但问题是我无法杀死所有32个进程,我尝试了一切
pkill -f pid/process name
killall -9 pid/process name
etc.,
我杀死进程的唯一成功方法是通过用户杀死它
pkill -u username
如何在不使用用户名的情况下终止这些过程?
非常感谢任何帮助
答案 0 :(得分:3)
杀死进程不会自动杀死其子进程。杀死bash脚本不会导致openssl speed
进程终止。
您可以使用kill
电话投放更广泛的网络,这就是您使用pkill -u
进行的操作。或者您可以在脚本中使用trap
并添加错误处理程序。
cleanup() {
# kill children
}
trap cleanup EXIT
答案 1 :(得分:2)
最后,我找到了解决自己问题的方法,
{
"name": "react-app",
"version": "1.0.0",
"description": "sample",
"scripts": {
"start": "webpack-dev-server"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dheeraja00/react-app.git"
},
"author": "Dheeraj Agrawal",
"license": "ISC",
"bugs": {
"url": "https://github.com/dheeraja00/react-app/issues"
},
"homepage": "https://github.comdheeraja00/react-app#readme",
"dependencies": {
"material-design-lite": "^1.2.1",
"react": "^15.3.2"
},
"devDependencies": {
"babel-core": "^6.18.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"css-loader": "^0.25.0",
"file-loader": "^0.9.0",
"node-sass": "^3.10.1",
"raw-loader": "^0.5.1",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.2"
}
}
其中PID是运行的任何一个进程的进程ID,这可以正常工作,但我愿意听取其他任何可用选项
来源:http://fibrevillage.com/sysadmin/237-ways-to-kill-parent-and-child-processes-in-one-command
答案 2 :(得分:0)
我有一个类似的问题和解决方案,我需要在一段时间后杀死NodeJS服务器。
为此,我启用了Job control,并使用jobs通过组ID杀死了异步进程:
set -m
./node_modules/.bin/node src/index.js &
sleep 2
kill -- -$(jobs -p)