From cd2f484ec1686bc3b0ff18958dfa54066d2293cc Mon Sep 17 00:00:00 2001
From: Matthew Webster <mwebster@jalapeno19.cluster.fmrib.ox.ac.uk>
Date: Tue, 18 Mar 2025 17:27:45 +0000
Subject: [PATCH] BF: Correctly kill the background eddy process(es)

---
 fsl_course/fdt1/test_topup_eddy.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fsl_course/fdt1/test_topup_eddy.sh b/fsl_course/fdt1/test_topup_eddy.sh
index 448b656..414d491 100755
--- a/fsl_course/fdt1/test_topup_eddy.sh
+++ b/fsl_course/fdt1/test_topup_eddy.sh
@@ -4,6 +4,8 @@
 # Tests topup, eddy, and gps.
 
 set -e
+# -m needed for correct jobs control
+set -m 
 set -x
 
 outdir=$1
@@ -40,15 +42,18 @@ if which eddy_openmp &> /dev/null; then
       --index=$subdatadir/index.txt --acqp=$subdatadir/acqparams.txt \
       --bvecs=$subdatadir/bvecs --bvals=$subdatadir/bvals \
       --fwhm=0 --topup=$outdir/topup_AP_PA_b0 --flm=quadratic \
-      --out=$outdir/eddy_unwarped_images & sleep 10; kill -s TERM $!
+      --out=$outdir/eddy_unwarped_images & 
 elif which eddy &> /dev/null; then
     eddy --imain=$subdatadir/dwidata --mask=$outdir/hifi_nodif_brain_mask \
       --index=$subdatadir/index.txt --acqp=$subdatadir/acqparams.txt \
       --bvecs=$subdatadir/bvecs --bvals=$subdatadir/bvals \
       --fwhm=0 --topup=$outdir/topup_AP_PA_b0 --flm=quadratic \
-      --out=$outdir/eddy_unwarped_image & sleep 10; kill -s TERM $!
+      --out=$outdir/eddy_unwarped_images &
 fi
 
+sleep 10
+kill %1
+
 cp $subdatadir/pre_baked/eddy_unwarped_images* $outdir
 
 # Finally, test the gps command, for generating bvecs
-- 
GitLab