我有这个 zsh 脚本。有没有更优雅的方法来做到这一点?
export PROCESSES_TO_QUIT='puma rake sidekiq spring rails ruby-debug phantomjs zeus passenger guard resque "node server.js"'
pgr() {
echo "Finding processes in list: $PROCESSES_TO_QUIT"
for x in `echo ${PROCESSES_TO_QUIT}`; do
pgrep -fl $x;
done
}
pgk() {
echo "Killing processes in list: $PROCESSES_TO_QUIT"
for x in `echo ${PROCESSES_TO_QUIT}`; do
pkill -fl $x;
done
}
pgkk() {
echo "Killing -9 processes in list: $PROCESSES_TO_QUIT"
for x in `echo ${PROCESSES_TO_QUIT}`; do
pkill -9 -fl $x;
done
}
答案1
您可以使用xargs
它们来分离它们并killall
针对每个执行:
echo $PROCESSES_TO_QUIT | xargs killall -9
答案2
也许尝试killall
:
% export PROCESSES_TO_QUIT='puma rake ...'
% export KILL_SIGNAL='killall -9 '
% eval $KILL_SIGNAL $PROCESSES_TO_QUIT