如何检查进程是否在Linux中运行?

时间:2022-03-26 16:24:27

I have a script which checks for a jar file and if its running echo's running else will execute the jar file. But the following command seems to return a different value every time I run my script

我有一个脚本,它检查一个jar文件,如果它运行的echo正在运行else将执行jar文件。但是每次运行脚本时,以下命令似乎都会返回不同的值

ps aux | grep some.jar | grep -v grep | wc -l

ps aux | grep some.jar | grep -v grep | wc -l

When I just run ps aux I can see a few no of same jar files but only one process is running.

当我运行ps aux时,我可以看到一些相同的jar文件,但只有一个进程正在运行。

Any there other ways to check for running jar file?

有没有其他方法来检查运行jar文件?

Can I use pgrep -fl java instead of the above command?

我可以使用pgrep -fl java而不是上面的命令吗?

2 个解决方案

#1


1  

Try this,

ps aux | grep [s]ome.jar | wc -l

i just tested it myself and should do the trick :-)

我只是自己测试,应该做的伎俩:-)

#2


0  

You could try something like something like pgrep -f java.*jarname

你可以尝试像pgrep -f java。* jarname这样的东西

pgrep -fl java will return all the processes whose command line includes "java".

pgrep -fl java将返回其命令行包含“java”的所有进程。

#1


1  

Try this,

ps aux | grep [s]ome.jar | wc -l

i just tested it myself and should do the trick :-)

我只是自己测试,应该做的伎俩:-)

#2


0  

You could try something like something like pgrep -f java.*jarname

你可以尝试像pgrep -f java。* jarname这样的东西

pgrep -fl java will return all the processes whose command line includes "java".

pgrep -fl java将返回其命令行包含“java”的所有进程。