English 中文(简体)
2. 符合某种模式的杀戮和重新启动多个过程
原标题:Kill and restart multiple processes that fit a certain pattern

我正试图写出一只手脚本,杀死所有与某种模式相符的进程,然后重新开始。 我可以展示以下进程:

ps -ef|grep ws_sched_600.sh|grep -v grep|sort -k 10

清单列出了重新发明过程:

user 2220258       1   0 16:53:12      -  0:01 /bin/ksh /../../../../../ws_sched_600.sh EDW02_env
user 5562418       1   0 16:54:55      -  0:01 /bin/ksh /../../../../../ws_sched_600.sh EDW03_env
user 2916598       1   0 16:55:00      -  0:01 /bin/ksh /../../../../../ws_sched_600.sh EDW04_env

但是,我对如何通过这一进程来杀谁不清?

问题回答

<代码>t 似乎没有必要。 您可使用<代码>awk印刷第二栏和xargs,将产出转换为“条码>技能

ps -ef | grep ws_sched_600.sh | awk  {print $2}  | xargs kill

或者,你可以使用<条码>pric<>/code>或<条码>,根据程序名称杀人:

pkill -f ws_sched_600.sh
pkill ws_sched_600.sh

如果你担心在可能无法提供杀手的多个平台上指挥你,

ps -ef | awk  /ws_sched_600/{cmd="kill -9 "$2;system(cmd)}

我认为,这是你期待的。

for proc in $(ps -ef|grep ws_sched_600.sh|sort -k 10)
do
    kill -9 proc
done

编辑:

当然,它使用xargs,越好。





相关问题
What does it mean "to write a web service"?

I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签