I am working with some embedded Linux distribution built with Yocto. I need to check in a sh script whether some app is running. When the app is running if statement is executed, but if app is not running the else statement is not executed and nothing is shown on a screen. I tested this piece of code on a PC and it works properly. Do you have any idea why this code doesn't work on my embedded Linux distribution? The only difference I can see is that on my embedded Linux
echo $SHELL shows /bin/sh and on PC it shows /bin/bash but it is very simple code and it should works both with bash and sh.
My code:
#!/bin/sh
check_status()
{
pid=`pidof -x my_app`
if [ -n "$pid" ]; then
echo "My_app is running."
else
echo "My_app is stopped."
fi
}
check_status
Thank you very much in advance for any help.
EDIT:
pidofis available on my embedded Linux.- I set my shell as
/bin/bashinstead of/bin/shand reboot the system. - I replaced the first line of my script with the following one:
#!/usr/bin/env bash.
Neither 2nd, nor 3rd solution solved my problem.