#! /opt/bin/dash
#
# os/prog/mlfq/post.sh
# uses non-standard --maxstart, --minlen, and --minio options
export PATH="/opt/bin:/bin:/usr/bin"
#echo "Content-type: text/plain\n"; in=$(cat); echo "in = \"$in\""; exit
echo "Content-type: text/html\n\n
MLFQ"
user=`echo "${REMOTE_USER}" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]'`
if [ -z "$user" ]; then echo "Bad user: ${REMOTE_USER} -> $user"; exit 1; fi
if [ -n "$HTTP_HOST" ]; then cd /os/prog/mlfq || exit 1; fi
# tomato = #FF6347
# lightgreen = #90EE90
#
in=$(cat | egrep -v '#FF6347|#90EE90')
h=$(echo "$in" | awk '{ if( $2 == "P") { print $3; exit; }}')
useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}')
q="1"; a="5"; maxlen="12"; maxio="7"; opt="--minlen 7 --maxstart 4 --minio 4"
case "$h" in
3) p="3"; s="123456789"; n="3"; j="3";;
2) p="2"; s="123456789"; n="2"; j="2";;
*) p="1"; s="123456789"; n="2"; j="2"; maxlen="10"; maxio="0"; opt="--minlen 5 --maxstart 4 --minio 1"
;;
esac
if [ -n "$useed" ]; then
seed="$useed"
msg="- seed = $seed"
else
x=$(perl -e "print unpack(\"C*\",$user);"); seed="${s}${x}"
#echo "s = $s, x = $x, seed = $seed
"
msg=""
fi
echo "$user - MLFQ #$p results $msg
green = correct |
red = wrong |
"
out=$(
(echo "$in"; python3 ./mlfq.py -s "$seed" -n "$n" -j "$j" -q "$q" -a "$a" \
--maxlen "$maxlen" --maxio "$maxio" $opt -c | grep '^\[ time '; echo "[ time 99999 ]") |
awk -v "nj=$j" 'BEGIN { t=0; for(j=0;jTime | ";
for(j=0;jJob "j""; } print "
"; } {
# each line of user input from mlfq-post looks like: U name value
if( $1 != "") { if( $1 == "U") u[$2]=$3; else {
time=$3; what=$5; if( time > t) { print ""t" | "; for(j=0;j"v"";
} print "
"; ++t;
for(j=0;j> log
fi
echo "$out"
# [ time 7 ] IO_START by JOB 1
# 1 2 3 4 5 6 7 8
#
# [ time 8 ] Run JOB 0 at PRIORITY 0 [ TICKS 0 ALLOT 1 TIME 7 (of 11) ]
# 1 2 3 4 5 6 7 8 9 10
#
# [ time 9 ] IO_START by JOB 0
# [ time 9 ] IDLE
# [ time 19 ] FINISHED JOB 1
# 1 2 3 4 5 6 7