Skip to content

Instantly share code, notes, and snippets.

@dpatti
Created February 24, 2012 18:24
Show Gist options
  • Save dpatti/1902719 to your computer and use it in GitHub Desktop.
Save dpatti/1902719 to your computer and use it in GitHub Desktop.
UpEnter Shell Script
$> ./upenter.sh 10000 ./test
parent
child
--------------------------------------------------------------------------------
child
parent
--------------------------------------------------------------------------------
Took 995 attempt(s) to get a different output
#include <stdlib.h>
#include <stdio.h>
int main() {
int rc;
rc = fork();
if (rc > 0) {
printf("parent\n");
} else {
printf("child\n");
}
return 0;
}
#!/bin/sh
exiting()
{
rm -f __1.out __2.out __err.out
exit
}
# First argument may be integer to indicate max iterations
max=50
case $1 in
[0-9]*)
max=$1
shift
;;
esac
# First run
rm -f __1.out
$@ >> __1.out 2>> __err.out
# Error check
if [ ! $? -eq 0 ]; then
cat __err.out
exiting
fi
n=1
while [ $n -le $max ]; do
# nth run
rm -f __2.out
$@ >> __2.out 2>> __err.out
# Error check
if [ ! $? -eq 0 ]; then
cat __err.out
exiting
fi
# Check output
diff -q __1.out __2.out > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
# Output differs
cat __1.out
echo --------------------------------------------------------------------------------
cat __2.out
echo --------------------------------------------------------------------------------
echo "Took ${n} attempt(s) to get a different output"
exiting
fi
# Increment and loop until $max
n=$((${n}+1))
done
# No difference found
cat __1.out
echo --------------------------------------------------------------------------------
echo "Could not find a different output in ${max} attempt(s)"
exiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment