Hi,
I have created a shell script file called terminal.sh which is placed in /etc/rc5.d in which it runs a Qt appliaction. I am trying implement a functionality in which the script waits for the application to finish running by checking the pid such as
if(process running ); then wait
I'm new to shell scripting, can anyone help?
my code is as below.
#! /bin/sh
terminalgui="/home/root/terminal"
ROTATION=""
GUI_OPTS="-qws $ROTATION terminal.pro"
PIDFILE="/var/run/terminal.pid"
test -x "$terminalgui" || exit 0
case "$1" in
start)
chvt 4
cd /usr/share/terminal
rm -rf tmp/*
rm -rf lock/*
cd -
if [ -e $PIDFILE ]; then
PIDDIR=/proc/$(cat $PIDFILE)
if [ -d ${PIDDIR} -a "$(readlink -f ${PIDDIR}/exe)" = "${terminalgui}" ]; then
echo "$DESC already started; not starting."
else
echo "Removing stale PID file $PIDFILE."
rm -f $PIDFILE
fi
fi
echo -n "Starting Terminal GUI application"
start-stop-daemon --start --quiet --background -m --pidfile $PIDFILE --exec $terminalgui -- $TERMINAL_OPTS
echo "."
if [$pid]; then
echo "process running"
else
echo "process not running"
fi
;;
stop)
echo -n "Stopping Terminal GUI application"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
*)
echo "Usage: /etc/init.d/terminal {start|stop}"
exit 1
esac
exit 0