Mr. Demetrius Michael
Mr. Demetrius Michael

Reputation: 2406

Nohup does not work in OSX

Bash:

$nohup sleep 10 &

but when I close the terminal:

will exit warning

Any ideas? ideally I want to run Mongodb in the background.

Upvotes: 13

Views: 15879

Answers (5)

user12365116
user12365116

Reputation: 11

use tmux

brew install tmux

tmux

use "tee" command to store output to txt

python hello.py | tee -a ~/Downloads/output.txt

Upvotes: 1

Jose Alban
Jose Alban

Reputation: 7956

I'm on OSX 10.8.5, and can confirm:

nohup base64 /dev/urandom &

Terminal.app-based apps (eg TotalTerminal) spawns the process under the shell session, not under launchd, which would be the expected/equivalent to linux behaviour.

On the other hand, iTerm2.app was able to run the same command under launchd, and it kept alive after the shell session was closed. It implements some special trick though:

─┬◆ 00001 root /sbin/launchd
 ├─┬◆ 00245 albanj01 /sbin/launchd
 │ └─┬◆ 21533 albanj01 /Applications/iTerm.app/Contents/MacOS/iTerm2 -psn_0_94628409
 │   └─┬◆ 04684 albanj01 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server /Applications/iTerm.app/Contents/MacOS/iTerm2 --launch_shell
 │     └─┬◆ 04685 albanj01 -zsh
 │       └──◆ 04759 albanj01 base64 /dev/urandom

My colleague on my side has tried the same thing on OSX 10.10.x and Terminal.app spawned the nohup process under launchd, suggesting that potentially they have fixed it between 10.8.x-10.10.x .

Upvotes: 2

Jon Shier
Jon Shier

Reputation: 12790

Running it in a screen session should work just fine.

Upvotes: 2

BillRobertson42
BillRobertson42

Reputation: 12883

I tried this on Snow Leopard, and the dialog popped up and complained that it was going to kill sleep, but when I checked via ps -eaf sleep was still running.

bill$ ps -eaf | grep sleep
  501 11806     1   0   0:00.00 ??         0:00.01 sleep 1000
  501 11811  2628   0   0:00.00 ttys001    0:00.00 grep sleep

Upvotes: 4

mpontillo
mpontillo

Reputation: 13967

Interesting. Seems like an issue specific to the default Terminal app. Because for what it's worth, iTerm2 doesn't exhibit this behavior. (so in other words, nohup is not actually broken on OS X; this just seems like special behavior in Terminal which looks for subprocesses on exit.)

In many ways, iTerm2 it's better than the default terminal. You should give it a try!

Upvotes: 7

Related Questions