I want to synchronize between processes. My computer has two cores. User can enter the simulation number from command line. If input is greater than 2, the 3rd and other processes have to wait until one of the earlier processes is finished. If one of them is finished, the next process should be started. For example, say the first two processes are already running. The first process finishes before the 2nd. Now the 3rd process should be start.
I am new in bash, I figured out. It is seen that anywait: command not found. How can I do that? Here is my script:
#!/bin/bash
# My first script
count=2
echo -n "Please enter the number of simulation :"
read number
echo "Please enter the algorithm type "
printf "0 for NNA\n1 for SPA\n2 for EEEA :"
while read type; do
case $type in
0 ) cd /home/cea/Desktop/simulation/wsnfuture
taskset -c 0 ./wsnfuture -u Cmdenv omnetpp.ini > /home/cea/Desktop/simulation/RESULTS/NNA/NNA0/0 &
taskset -c 1 ./wsnfuture -u Cmdenv omnetpp.ini > /home/cea/Desktop/simulation/RESULTS/NNA/NNA0/1 &
while [ $count -lt $number ]; do
anywait
cd /home/cea/Desktop/simulation/wsnfuture
mkdir /home/cea/Desktop/simulation/RESULTS/NNA/NNA$count
taskset -c $((count % 2)) ./wsnfuture -u Cmdenv omnetpp.ini > /home/cea/Desktop/simulation/RESULTS/NNA/NNA$count/$count &
count=$((count + 1))
done
;;
1 ) while [ $count -lt $number ]; do
cd /home/cea/Desktop/simulation/wsnfuture1
taskset -c $((count % 2)) ./wsnfuture -u Cmdenv omnetpp.ini > /home/cea/Desktop/simulation/RESULTS/SPA/$count &
count=$((count + 1))
done
;;
2 ) while [ $count -lt $number ]; do
cd /home/cea/Desktop/simulation/wsnfuture2
taskset -c $((count % 2)) ./wsnfuture -u Cmdenv omnetpp.ini > /home/cea/Desktop/simulation/RESULTS/EEEA/$count &
count=$((count + 1))
done
;;
* ) echo "You did not enter a number"
echo "between 0 and 2."
echo "Please enter the algorithm type "
printf "0 for NNA\n1 for SPA\n2 for EEEA :"
esac
done
function anywait(){
while ps axg | grep -v grep | grep wsnfuture> /dev/null; do sleep 1; done
}