Skip to content

Instantly share code, notes, and snippets.

@larytet
Last active July 7, 2017 16:43
Show Gist options
  • Save larytet/10ceddea609d2da17aa09558ed0e04bc to your computer and use it in GitHub Desktop.
Save larytet/10ceddea609d2da17aa09558ed0e04bc to your computer and use it in GitHub Desktop.
Tight echo loop
#!/bin/bash
function echo_loop()
{
file=echo_file_`date +%s%N`
echo $file
echo > $file
counter=1
end=$((SECONDS+10))
while [ $SECONDS -lt $end ]; do
echo $counter >>$file
counter=$((counter+1))
done
tail -n 1 $file
rm -f $file
}
CPUS=`grep -c ^processor /proc/cpuinfo`
pids=""
counter=0
while [ $counter -lt $CPUS ]; do
echo_loop &
pids="$pids $!"
counter=$(($counter+1))
done
wait $pids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment