shell脚本来捕获进程ID,如果存在杀死它 [英] Shell script to capture Process ID and kill it if exist

查看:165
本文介绍了shell脚本来捕获进程ID,如果存在杀死它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这code和它不工作

I tried this code and it is not working

#!/bin/sh

#Find the Process ID for syncapp running instance

PID=`ps -ef | grep syncapp 'awk {print $2}'`

if [[ -z "$PID" ]] then
Kill -9 PID
fi

这是显示AWK附近一个错误。

It is showing a error near awk.

任何建议,请。

推荐答案

其实这样做是通过杀象下面参数的最简单的方法:

Actually the easiest way to do that would be to pass kill arguments like below:

ps -ef | grep your_process_name | grep -v grep | awk '{print $2}' | xargs kill

希望它帮助。

这篇关于shell脚本来捕获进程ID,如果存在杀死它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆