Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nohup does not work in OSX

Tags:

bash

macos

nohup

Bash:

$nohup sleep 10 &

but when I close the terminal:

will exit warning

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

like image 616
Mr. Demetrius Michael Avatar asked Feb 26 '12 05:02

Mr. Demetrius Michael


2 Answers

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 .

like image 124
Jose Alban Avatar answered Nov 15 '22 17:11

Jose Alban


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
like image 45
Bill Avatar answered Nov 15 '22 17:11

Bill