如何将 sbt 作为守护进程运行?

编程入门 行业动态 更新时间:2024-10-06 08:30:06
本文介绍了如何将 sbt 作为守护进程运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试过 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 作为守护进程运行?

本文发布于:2023-11-23 22:01:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   进程   sbt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!