我试过 nohup "sbt run" &
returns : nohup: failed to run command ‘sbt run’: No such file or directory
并尝试过:
nohup sbt run & [2] 7897 # nohup: ignoring input and appending output to ‘nohup.out’当我回车期望进程继续运行时,我收到:
When I carriage return expecting process to continue running I receive :
[2]+ Stopped nohup sbt run如何将 sbt 作为守护进程运行?
How to run sbt as a daemon ?
更新:
sbt run </dev/null & [5] 8961我想 cd up 一个目录:
I think cd up one dir :
# cd .. [5]+ Stopped sbt run < /dev/null (wd: /home/sum) (wd now: /home)所以它作为守护进程启动,但是如果我执行任何操作,例如更改目录,它会杀死进程吗?如何保持进程运行?
So it starts as daemon but if I perform any actions such as changing dir it kills the process ? How to keep process running ?
推荐答案看起来 sbt 从您的终端请求输入.如果它真的不需要输入(当你在后台运行程序时可能就是这种情况),你可以这样运行它:
Looks like sbt requested input from your terminal. If it does not really need input (which is probably the case when you run program in background), you can run it like this:
sbt run </dev/null >output-file &有关详细信息,请参阅此答案.
See this answer for details.
编辑
好的,现在这是一个难题.简短的回答:运行 sbt 如下:
Ok, now that was a puzzle. Short answer: run sbt as follows:
setsid nohup sbt run &理由:
sbt 停止的原因是SIGTTOU 信号的到来.它在几种情况下被传递到后台进程,包括修改终端配置.这是我们的例子,因为根据 strace -f sbt run &,sbt 在幕后做了很多黑魔法,如下所示:
The reason why sbt stops is arrival of SIGTTOU signal. It is delivered to background process in several cases, which include modifying terminal configuration. This is our case because according to strace -f sbt run &, sbt does a lot of black magic under the hood like this:
[pid 16600] execve("/usr/bin/sh", ["sh", "-c", "stty -g < /dev/tty"], [/* 75 vars */] <unfinished ...>要解决这个问题,您可以在不同的会话中运行 sbt 以将其与当前终端分离,这样它就不会打开/dev/tty 并弄乱我们的终端.
To work this around, you can run sbt in a different session to detach it from current terminal, so that it won't open /dev/tty and mess with our terminal.
更多推荐
如何将 sbt 作为守护进程运行?
发布评论