Embedded beginners, the first time to upload code. Yesterday did a UDHCPD and Udhcpc Guardian, currently only with Shell imitation writing, what method can do guardian?
#! /bin/sh
#进程名字可修改
pro_name=udhcpc
wlan=ra0 while
true;
# get $pro_name number of processes with PS
num= ' PS aux | grep ${pro_name} | grep-v grep |wc-l '
# Echo $NUM
# less than 1, restart process
if ["${num}"-lt "1"];then
echo "${pro_name} was Killed "
${pro_name}-I ${wlan}
# greater than 1, kill all Processes, reboot
elif [" ${num} "-gt" 1 "];then
echo" more than 1 ${pro_name},killall ${pro_name} "
killall-9 $PRO _name
${pro_name}-I ${wlan}
fi
# kill zombie Process
num_stat= ' ps aux | grep ${pro_name} | grep T | grep-v grep | wc-l '
if ["${num_stat}"-gt "0"];then
Kil Lall-9 ${pro_name}
${pro_name}-I ${wlan}
fi done
exit 0
The above is the entire contents of this article, I hope to be familiar with the Linux shell script to help.