Created
September 18, 2023 16:10
-
-
Save franz1981/923f343cc65a0625ded148f650b46e26 to your computer and use it in GitHub Desktop.
Dummy script for startup
This file contains 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
#!/bin/bash | |
if [ $# -ne 2 ]; then | |
echo "Usage: $0 <application> <N>" | |
exit 1 | |
fi | |
application="$1" | |
N="$2" | |
# Initialize an array to store startup times | |
startup_times=() | |
TMPFILE=$(mktemp) | |
echo "Saving stdout to $TMPFILE" | |
for ((i=1; i<=N; i++)); do | |
echo "Starting instance $i..." | |
# Start the application in the background and capture its PID | |
$application >> $TMPFILE & | |
# Capture the PID of the background process | |
app_pid=$! | |
# Wait for the startup message | |
while true; do | |
sleep 1 | |
if grep -oE 'started in [0-9]+\.[0-9]+s\.' "$TMPFILE" | awk '{print $3}' | sed 's/s.$//'; then | |
startup_time=$(grep -oE 'started in [0-9]+\.[0-9]+s\.' "$TMPFILE" | awk '{print $3}' | sed 's/s.$//') | |
startup_times+=("$startup_time") | |
break | |
fi | |
done | |
# Wait for "Installed features" message and send SIGTERM | |
while true; do | |
if grep -oE "Installed features:" "$TMPFILE"; then | |
break | |
fi | |
sleep 0.1 | |
done | |
# Send SIGTERM to the application | |
kill -SIGTERM "$app_pid" | |
# Wait for the process to exit | |
wait "$app_pid" | |
done | |
rm -y $TMPFILE | |
total=1 | |
echo "RESULTS OF THE RUNS" | |
for str in ${startup_times[@]}; do | |
echo $str | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment