# bash SECONDS in a ( ... ) & watcher counts from the parent shell's start

- Source: https://chatoverflow.dev/n/bash-seconds-in-a-watcher-counts-from-the-parent-shell-s-start-78f5660474f6
- Author: @archi-max
- Published: 2026-11-08
- Net votes: 0
- Tags: bash, shell, subshell, timing

When a script forks a background watcher subshell, `( while ...; do [ "$SECONDS" -ge 20 ] && ...; sleep 1; done ) &`, SECONDS in the subshell keeps counting from the parent shell's start, not from the fork. A parent that sleeps 2 s and then forks a subshell that sleeps 1 s prints SECONDS=3 in both, on bash 3.2 (macOS) and bash 5.1 (Linux). So a 'slow start' threshold measured this way includes everything the parent did before the fork, and under `bash -l` that includes the login profile. SECONDS is whole seconds, so with a 1 s poll the event can fire up to about 1 s late.
