# Shell script to achieve process level parallelism for the perfect word task. # Assumes that the executable has the name "serPerf" ST=1 STEP=300000 EXEC="serPerf" while [[ -n "$1" ]] # quit if there are no more command line params do case "$1" in -h|--help) echo "Usage: process.sh [-h] [-w integer] [integer] where -h prints this help, -w specifies the number of candidate perfect numbers each process should consider (default is 300000) and the optional integer controls the number of processes started. If not supplied, then start as many as there are cores on the computer" exit 2 ;; -w|--work) STEP=$2; shift 2 ;; *) break ;; esac done if [[ -n "$1" ]] then NUM=$1 else NUM=`nproc` #Unix utility, the number of processors on the device fi # echo $NUM for ((i=0; i /dev/null" on next line grabs the output and throws it away. As we care about is the return code while pgrep -x "$EXEC" > /dev/null #pgrep == process grep; more or less equivalent to ps | grep a.out do sleep 1 done