Linux bashshell脚本显示分段错误
我的shell脚本在启动时打印分段错误 watchdog.sh:Linux bashshell脚本显示分段错误,linux,bash,shell,Linux,Bash,Shell,我的shell脚本在启动时打印分段错误 watchdog.sh: #!/bin/bash while true do processCnt=`ps ax | grep $1 | grep -v grep | grep -v watchdog | wc -l` if [ $processCnt -lt 1 ]; then $1 fi sleep 2 done ./watchdog.sh hqservicedemon & ./watch
#!/bin/bash
while true
do
processCnt=`ps ax | grep $1 | grep -v grep | grep -v watchdog | wc -l`
if [ $processCnt -lt 1 ]; then
$1
fi
sleep 2
done
./watchdog.sh hqservicedemon &
./watchdog.sh relayservicedemon &
./watchdog.sh rtspservicedemon &
./watchdog.sh httpcontrolservicedemon &
脚本获取程序名作为参数我还在run.sh中同时使用不同的参数运行该脚本4次 run.sh:
#!/bin/bash
while true
do
processCnt=`ps ax | grep $1 | grep -v grep | grep -v watchdog | wc -l`
if [ $processCnt -lt 1 ]; then
$1
fi
sleep 2
done
./watchdog.sh hqservicedemon &
./watchdog.sh relayservicedemon &
./watchdog.sh rtspservicedemon &
./watchdog.sh httpcontrolservicedemon &
运行run.sh时,出现错误:
./watchdog.sh: line xx: 7316 segmentation fault (core dumped)
经过一些测试后,在run.sh中只运行一个watchdog.sh时,它看起来是正常的。我在shell脚本中做错了什么
谢谢你的建议
编辑:
我的恶魔有问题,不是剧本。修复demon后,脚本运行良好。可能是您的demon的一个缺陷导致seg故障,而不是脚本。它发现恶魔没有运行,执行它(可能没有正确的参数?)和seg故障。 试着跑四个
现在已经有很多工具可以让这些东西保持活力,而无需编写新的脚本来管理它们。如果您使用的是运行upstart的系统,那么使用upstart可以非常轻松地做到这一点。其他系统也有类似的方法来实现这一点,我不会自己从头开始编写。这可能是你的恶魔之一,它是seg故障,而不是脚本。它发现恶魔没有运行,执行它(可能没有正确的参数?)和seg故障。 试着跑四个
现在已经有很多工具可以让这些东西保持活力,而无需编写新的脚本来管理它们。如果您使用的是运行upstart的系统,那么使用upstart可以非常轻松地做到这一点。其他系统也有类似的方法,我不会从头开始写的。考虑使用管道代替<代码> PS <代码> >代码> GRP。考虑使用管道代替<代码> PS <代码> >代码> GRP。谢谢您的快速回复。我将检查我的demon and upstart工具。最后,我发现我的demon有问题,而不是脚本。听起来好像一个正确的答案即将出现:)谢谢你的快速回复。我将检查我的demon and upstart工具。最后,我发现我的demon有问题,而不是脚本。听起来正确的答案是:)