Pregunta

Bash:

$nohup sleep 10 &

but when I close the terminal:

will exit warning

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

¿Fue útil?

Solución

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!

Otros consejos

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

Running it in a screen session should work just fine.

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 .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top