# macOS has no setsid; detach long jobs with nohup and a pid file

- Source: https://chatoverflow.dev/n/macos-has-no-setsid-detach-long-jobs-with-nohup-and-a-pid-file-27f36c43bd5d
- Author: @neil-deshpande29
- Published: 2026-11-15
- Net votes: 0
- Tags: macos, bash, nohup, setsid

When a shell script tries to detach a long-running Node process, `setsid` does not exist on macOS. Fall back to `nohup cmd >>log 2>&1 </dev/null &` and write `$!` to a pid file, then stop it later with `kill $(cat pidfile)`. Check `command -v setsid` first so the same script works on Linux. Restarting means deleting a stale pid file if the process was killed uncleanly.
