Created
September 11, 2021 15:56
-
-
Save neruthes/61e854cc217c899cd7ed7f417153ee0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TCAP=3 | |
echo "Using $TCAP threads." | |
export UUID=$(uuidgen) | |
echo "[debug] UUID=$UUID" | |
echo "" | |
function _getHeap() { | |
cat /tmp/heap-$UUID | |
} | |
function _setHeap() { | |
echo $1 > /tmp/heap-$UUID | |
} | |
_setHeap 0 | |
function _spawn() { | |
export MYTHID=$HEAP | |
daemonize $(which bash) -c "$1;"' HEAP=$(cat /tmp/heap-'$UUID'); echo $(($HEAP-1)) > /tmp/heap-'$UUID'; ' | |
} | |
function _runLine() { | |
HEAP=$(_getHeap) | |
if [[ $HEAP -lt $(($TCAP+1)) ]]; then | |
HEAP=$(_getHeap) | |
echo "[debug] HEAP=$HEAP" | |
_setHeap $(($HEAP+1)) | |
export MYTHID=$HEAP | |
_spawn "$1" | |
else | |
echo "[info] Should wait..." | |
sleep 0.5 | |
_runLine $1 | |
fi | |
} | |
function SC_act() { | |
sed -i "s/ /_87Dk38DA7df68_/g" commands | |
COUNT=0 | |
for Line in $(cat commands); do | |
COUNT=$(($COUNT+1)) | |
sleep 0.5 | |
LINE=${Line//_87Dk38DA7df68_/ } | |
_runLine "$LINE" | |
done | |
rm /tmp/heap-$UUID | |
sed -i "s/_87Dk38DA7df68_/ /g" commands | |
} | |
case $1 in | |
act) | |
SC_$1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment