12

I use nohup to run a command from a php application (I have a web page that sends POST request to php server to start a shell script in background).

It's something like

exec('nohup /home/user/test.sh > /home/user/test.log 2>&1 &')

This worked fine when I was using OS X Snow Leopard (OS X 10.6). However, recently I upgraded my MAC to OS X Yosemite (OS X 10.10) and now it doesn't work any more.

In the test.log, I always get the message: nohup can't detach from console: no such file or directory.

If I just run the same command in bash directly, it works fine. I did a lot of searching, but seems like I can't find anything useful for this issue. What I only see is a discussion regarding Jenkins, it seems like they also see similar issue.

Anyone has any idea about why it starts to fail with Yosemite? Any input will be appreciated.

Nic
  • 12,220
  • 20
  • 77
  • 105
weilan
  • 121
  • 1
  • 4
  • Perhaps you should ask this on http://apple.stackexchange.com/ instead. – Jeen Broekstra Mar 18 '15 at 01:01
  • I'm running Yosemite too and I checked – nohup works fine on my computer, I tried calling it the same way. But why do you even need it? Why not just do exec('/bin/sh /home/user/test.sh > /home/user/test.log 2>&1 &')? All nohup does is to ignore SIGHUP signals but I'm guessing you are not using any signals anyway. Background mode is triggered by '&' symbol in the end, not by nohup. – Denis Mysenko Mar 18 '15 at 01:10
  • Thanks. Yes I removed nohup it works fine. But just in case in the future I need it, then it will be hard time for me... It's really strange to me for this issue – weilan Mar 19 '15 at 02:00
  • I am facing same issue with my yosemite. Did the problem get fixed – amrk7 Apr 07 '15 at 17:02
  • No, no lucky to get it resolved. Just remove nohup to get it running – weilan Apr 08 '15 at 19:05

3 Answers3

24

Are you running in tmux? I just had this issue, started a new terminal without tmux, and that worked fine.

See this tmux issue to explain why this happens. It stems from a quirk in OS X. https://github.com/tmux/tmux/issues/443

Bradley Kaiser
  • 776
  • 4
  • 16
1

I had a similar problem when running a command on a mac mini from an ssh login, the error I got was:

nohup: can't detach from console: Undefined error: 0

I fixed the problem by removing "nohup" and redirecting stdin, the command that worked and survived "exit" looked like:

my_command < /dev/null > /dev/null 2> error.txt &
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

This broke for nohup and screen from 10.11.6 -> 10.12.6. The fix is to enable UsePAM in /etc/ssh/sshd_config. We found out that after ssh'ing and doing a su - $USER , then nohup would work. Then while trying other versions of sshd and trying to get password auth working, discovered that setting UsePAM yes fixed the problem (changing sshd versions did not help).

sabujp
  • 989
  • 1
  • 11
  • 12