Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash shell script shows segmentation fault

Tags:

linux

bash

shell

my shell script prints segmentation fault when it starts.

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

Script gets a program name as a parameter.
I also run this script 4 times with different parameter at the same time in run.sh.

run.sh :

./watchdog.sh hqservicedemon &
./watchdog.sh relayservicedemon &
./watchdog.sh rtspservicedemon &
./watchdog.sh httpcontrolservicedemon &

When I run run.sh I get error:

./watchdog.sh: line xx:  7316 segmentation fault (core dumped)

After some tests it looks like OK when running just one watchdog.sh in run.sh.
What am I doing wrong in shell script?
Thank you for any advice.

Edited: My demon has a problem, not a script. After fix demon, script works well.

like image 308
Winter Singha Avatar asked Jun 13 '26 11:06

Winter Singha


1 Answers

it is probably one of your demon's that is seg faulting and not the script. It is finding that the demon is not running, executes it (maybe without proper arguments?) and seg faults. try to run the four

There are already many tools to keep those things alive without you writing a new script to manage it. If you are using a system that runs upstart you can do this very easily with upstart. other systems have similar ways to do this, i would not write it from scratch myself.

like image 144
Born2Code Avatar answered Jun 16 '26 07:06

Born2Code