如何编写一个以编程方式杀死进程的shell脚本?

时间:2010-06-28 10:17:07

标签: solaris

我一直在使用以下方式手动终止进程

ps -ef | grep process
kill -9 process id of process
start the process again

但我认为如何以编程方式执行它,就像在shellcript中写一样 我只需要运行,例如./restartProcess.sh

由于

1 个答案:

答案 0 :(得分:1)

使用编辑器创建名为restartProcess.sh

的文件
kill $(pgrep process)
start the process again 

将上面的内容放入其中,然后chmod + x restartProcess.sh

几点 -

只需使用kill pid,如果编写得相当好,就可以清理进程。

kill $(pgrep process)

是脚本前两行的solaris版本。