使用 Shell 脚本检查进程 [英] Check Process using Shell Script
本文介绍了使用 Shell 脚本检查进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个 Java 程序,它检查正在运行的进程,如果没有启动该进程.在我的上下文中,我正在执行这样的 .sh 文件.
I am developing a Java program which checks the running processes, if not start that process. In my context I am executing the .sh file which is like this.
#!/bin/sh
echo "Hello World..."
cnt=`ps -eaflc --sort stime | grep clientApplication.jar | grep -v grep | wc -l`
if [ $cnt = 3 ]
then
echo "Services for Pigeon are already running..."
else
echo "Starting Services for Pigeon..."
echo `java -jar clientApplication.jar`
fi
但它不起作用.有什么问题?
But it's not working. What's the problem?
推荐答案
使用测试表达式有效.希望这会有所帮助!!
Using the test expression works. Hope this helps !!
echo "Hello World"
cnt=`ps -eaflc --sort stime | grep clientApplication.jar |grep -v grep | wc -l`
if(test $cnt -eq 3) ;
then
echo "Services for Pigeon are already running..."
else
echo "Starting Services for Pigeon..."
echo `java -jar clientApplication.jar`
fi
这篇关于使用 Shell 脚本检查进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文