linux - 如果死了就开始进程

标签 linux bash process daemon

我正在尝试做的是在没有启动的情况下启动一个进程。这是我的尝试

#!/bin/bash
pid=`ps ax | grep app | grep -v grep | wc -l`
  if [ $pid = 0 ]
then
 /etc/init.d/app start
fi

问题是线路

/etc/init.d/app start

未执行。这里有什么问题? 我知道我可以使用 daemontools,但我喜欢“bash”方法。

最佳答案

看看 == 运算符。

最好的可能是这样的

pid=`ps ax | grep app | grep -v grep`
test -z "$pid" && /etc/init.d/app start

关于linux - 如果死了就开始进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9992809/

相关文章:

linux - 为什么我的汇编代码应该在 O(N*sqrt(N)) 时间内运行,但它却在线性时间内运行?

自动运行时 Bash 脚本无法正常工作

bash - 如何在 bash 脚本中运行这两个 heroku 命令?

c++ - 多次加载同一个dll

c - 将进程置于前台

python - 多处理和全局管理器

linux - 使用 RS 和 RT 在 awk 命令中匹配多个字符串

linux - 为什么/etc/profile.d 只在SSH 登录时使用?

Linux shell脚本如何仅在表不存在时创建Oracle表

python - 如何通过在终端单独输入​​名称来运行 python 程序?