Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nohup doesn't work with OS X Yosmite - get error "can't detach from console no such file or directory"

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.

like image 525
weilan Avatar asked Mar 18 '15 00:03

weilan


2 Answers

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 &
like image 193
Arthur Stephens Avatar answered Oct 09 '22 09:10

Arthur Stephens


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

like image 27
Bradley Kaiser Avatar answered Oct 09 '22 10:10

Bradley Kaiser