When a port is "already in use" — find the offending process and (carefully) kill it. `lsof` is the gold standard; `ss` is the lighter modern alternative.
Use `trap` to delete temp files / kill background workers when the script exits — even on Ctrl-C or an unhandled error. Single most-undervalued bash feature.
`timeout` (GNU coreutils) kills a command after N seconds. Returns exit code 124 on timeout — let the caller distinguish "timed out" from "failed for other reasons."
Write a daemon's PID to a file at start, check on subsequent runs, clean up on exit. Avoids two copies of the same daemon when the script is invoked twice.
`<(...)` makes a command's output look like a file; `>(...)` makes a command's input look like a file. Killer feature for tools that only accept filenames.
`xargs -P N` is a Swiss-army knife for parallel map: feed it a list of inputs and a command, it runs N workers. Faster and simpler than bash for-loops with `&`.