···136136mkdir -p "$TMPDIR"
137137OUTPUT_FILE=$(mktemp --tmpdir="$TMPDIR")
138138139139-# Launch systemd-run, tee stderr to file and also to terminal
140140-"${CMD[@]}" 2> >(tee "$OUTPUT_FILE" >&2)
141141-EXIT_CODE=$?
139139+# Launch systemd-run in background, tee stderr to file and also to terminal
140140+"${CMD[@]}" 2> >(tee "$OUTPUT_FILE" >&2) &
141141+RUN_PID=$!
142142+143143+# Wait for scope to be created and systemd-run output to be captured
144144+sleep 0.3
142145143146# Read output and extract scope unit name from stderr
144147RUN_OUTPUT=$(cat "$OUTPUT_FILE")
···173176 set_cgroup_property "io.weight" "default 1" "io.weight to minimum"
174177 set_cgroup_property "io.prio.class" "idle" "io.prio.class to idle"
175178179179+ # Set CPU affinity (AllowedCPUs property doesn't work, set cpuset directly)
180180+ set_cgroup_property "cpuset.cpus" "$CPU_AFFINITY" "CPU affinity to $CPU_AFFINITY"
181181+176182 # Set CPU scheduling to batch via chrt (done pre-launch via CMD wrapping)
177183 # Note: cpuset and scheduling policies are set via chrt -b 0 in command wrapper
178184 # Post-launch cgroup does not support direct scheduling policy changes
179185fi
186186+187187+# Wait for the background process to finish
188188+wait $RUN_PID
189189+EXIT_CODE=$?
180190181191# Clean up temporary file
182192rm -f "$OUTPUT_FILE"