如何编写一个.sh来获取应用程序的进程id,然后停止应用程序?
例如,我需要使用一个名为SomeApp的应用程序,但它通常需要重新启动,因此我需要键入“ps-ef | grep SomeApp”,然后键入“kill-9 7777” 首先查找进程id,然后停止该进程:如何编写一个.sh来获取应用程序的进程id,然后停止应用程序?,sh,Sh,例如,我需要使用一个名为SomeApp的应用程序,但它通常需要重新启动,因此我需要键入“ps-ef | grep SomeApp”,然后键入“kill-9 7777” 首先查找进程id,然后停止该进程: XXXX:~ XXXX$ ps -ef | grep SomeApp 333 7777 1 0 1:40PM ?? 0:40.31 /Users/XXXX/SomeApp 333 8888 9999 0 1:58PM abcd000 0:00.00
XXXX:~ XXXX$ ps -ef | grep SomeApp
333 7777 1 0 1:40PM ?? 0:40.31 /Users/XXXX/SomeApp
333 8888 9999 0 1:58PM abcd000 0:00.00 grep SomeApp
XXXX:~ XXXX$ kill -9 7777
现在我想将命令放入.sh,但我有一些东西不知道如何写入.sh:
ps -ef | grep 'SomeApp' | grep -v grep | awk '{print $2}' | xargs kill
或者查看pgrep
和pkill
,具体取决于操作系统 或者,允许您按名称终止进程。。。