diff --git a/how-many-subshells.sh b/how-many-subshells.sh new file mode 100755 index 0000000..6d98d14 --- /dev/null +++ b/how-many-subshells.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +NPROC=$(grep -c ^processor /proc/cpuinfo) +RESULTS_FOLDER=$(mktemp --dir) + +# Checking ulimit +if [[ $(ulimit) == "unlimited" ]];then + ULIMIT_YES="no" + while [[ $ULIMIT_YES == "no" ]] + do + read -p "ulimit is unlimited. This may not go well for the system. Are you sure? (yes/no): " ULIMIT_YES + if [[ $ULIMIT_YES == "yes" ]];then + break + elif [[ $ULIMIT_YES == "no" ]];then + exit + fi + done +fi + +# Run the job with n number of nprocs +find ./jobs -type f -name "*.sh" | \ +while read JOB_NAME +do + printf "Starting on job $JOB_NAME...\n" + SCALE=1 + CURRENT=9998 + BEFORE=9999 + RESULT_FILE="$RESULTS_FOLDER/$(basename $JOB_NAME)" + printf "Result file: $(readlink -f $RESULT_FILE)\n" + while [[ $(echo "$CURRENT < $BEFORE" | bc) -eq 1 ]] + do + BEFORE=$CURRENT + PARALLEL=$(( $NPROC * $SCALE )) + CURRENT=$( \ + /bin/time --format "%e" \ + bash -c "seq 1 10000000 | xargs -P $PARALLEL bash $JOB_NAME >/dev/null 2>&1" 2>&1 | \ + tee -a $RESULT_FILE \ + ) + (( SCALE++ )) + done + + # Display the results + awk -v nproc="$NPROC" '{print NR*nproc, $0}' $RESULTS_FOLDER/* + +done + +rm -rf $RESULTS_FOLDER diff --git a/jobs/curl_google.sh b/jobs/curl_google.sh new file mode 100755 index 0000000..3ca05a9 --- /dev/null +++ b/jobs/curl_google.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +curl -q https://www.google.com