diff --git a/startup-test.sh b/startup-test.sh index 567ffd7..ef82b55 100644 --- a/startup-test.sh +++ b/startup-test.sh @@ -17,25 +17,32 @@ sleep 1 # Démarrer la caméra echo "Starting the camera" /mnt/win/Users/BreizhHardware/Nextcloud/Programation/C++/Modelec/Initialisation/test/test3.sh & +sleep 1 # Démarrer l'IHM echo "Starting the IHM" /mnt/win/Users/BreizhHardware/Nextcloud/Programation/C++/Modelec/Initialisation/test/test4.sh fullscreen & -# Fonction pour surveiller la fermeture de l'IHM -monitor_ihm() { - while pgrep -x "test4.sh" > /dev/null; do - sleep 1 +# Fonction pour surveiller la fermeture de tous les programmes +monitor_all() { + local pids=$(pgrep -d ' ' -f "test1|test2|test3|test4") + + # Attendre que l'un des programmes se termine + wait $pids + + # Terminer tous les autres programmes + for pid in $pids; do + if ps -p $pid > /dev/null; then + echo "Program with PID $pid has terminated, stopping other programs" + pkill -P $$ -f "test1|test2|test3|test4" + break + fi done - # Une fois l'IHM fermée, tuer tous les autres programmes - killall test1.sh - killall test2.sh - killall test3.sh - echo "All programs terminated." + echo "All programs have terminated" } # Démarrer la fonction de surveillance en arrière-plan -monitor_ihm & +monitor_all & # Attendre que tous les programmes se terminent wait diff --git a/test/test1.sh b/test/test1.sh index bc3f24b..e6f1854 100644 --- a/test/test1.sh +++ b/test/test1.sh @@ -2,4 +2,5 @@ while true; do echo "test1" + sleep 1 done \ No newline at end of file diff --git a/test/test2.sh b/test/test2.sh index 933a4f8..5066fe9 100644 --- a/test/test2.sh +++ b/test/test2.sh @@ -2,4 +2,5 @@ while true; do echo "test2" + sleep 1 done \ No newline at end of file diff --git a/test/test3.sh b/test/test3.sh index 404fb0c..c6f6855 100644 --- a/test/test3.sh +++ b/test/test3.sh @@ -2,4 +2,5 @@ while true; do echo "test3" + sleep 1 done \ No newline at end of file diff --git a/test/test4.sh b/test/test4.sh index c99dff4..e434181 100644 --- a/test/test4.sh +++ b/test/test4.sh @@ -2,9 +2,8 @@ # Boucle pendant 10 secondes SECONDS=0 -while [ $SECONDS -lt 2 ]; do +while [ $SECONDS -lt 10 ]; do echo "test4" - sleep 1 done # Quitter le programme