I maintain an application that runs as a background service, started either on boot as a StartupItem or manually from the command line. I want to know how to launch it manually without having a controlling terminal, or completely detach after launching.
Using TextEdit to illustrate, I know that if it's launched from Terminal, it blocks the prompt until the program is quit, and will close if the terminal window is closed.
Both can be avoided by adding
& to the command, respectively:
nohup /Applications/TextEdit.app/Contents/MacOS/TextEdit &
disown can be used instead of
/Applications/TextEdit.app/Contents/MacOS/TextEdit & disown $!
Although TextEdit will stay running if the terminal window is closed, a warning will still be thrown. This is because TextEdit still has a controlling terminal, as indicated by
$ ps -ax | grep TextEdit 28390 ttys003 0:00.12 /Applications/TextEdit.app/Contents/MacOS/TextEdit
It's not until the terminal window is closed that TextEdit finally is TTY-free.
$ ps -ax | grep TextEdit 28390 ?? 0:00.12 /Applications/TextEdit.app/Contents/MacOS/TextEdit
I know it's possible to start the service without a controlling terminal with direct system calls, because when the StartupItem is used to start the service (either on boot or with SystemStarter), it starts without a TTY. My question is, can this also be accomplished using just the command line?