#!/bin/bash
# The number of processes adopted by init are counted for each execution of chain with a random number of processes

COUNTER=0
ITERATIONS=5

echo Executing simplechain program...
echo --------------------------------
while [ $COUNTER -lt $ITERATIONS ]; do
  let COUNTER=COUNTER+1
  NPROCS=$(( $RANDOM % 100 + 1 ))
  SLEEPTIME=$(( $RANDOM % 10 + 1 ))
  NITER=$(( $RANDOM % 5 + 1 ))

  echo Experiment $COUNTER of $ITERATIONS
  echo --------------------------------
  echo Number of processes = $NPROCS
  echo Sleep \time between fprintf = $SLEEPTIME 
  echo Iterations of fprintf = $NITER
  echo Observed count of adopted processes from fprintf / Number of fprintf calls = $(./chain -p $NPROCS -s $SLEEPTIME 2>&1 >/dev/null | grep 'parent ID: 1 ' | wc -l) / $(($NPROCS * $NITER))
  echo --------------------------------

done