关闭终端运行后在后台进程 [英] Running process in background after closing terminal

查看:165
本文介绍了关闭终端运行后在后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想即使在关闭终端后,在后台运行的脚本。我已经搜查,搜查,并试图的nohup 不认但既不似乎工作。当我关闭一个终端窗口,我得到的典型关闭此窗口将终止正在运行的进程:手表消息。这结束了结束我的后台进程,使用的nohup 不认时也是如此。可能是什么问题?

I am trying to run a script in the background even after closing the terminal. I have searched and searched and tried nohup and disown but neither seem to be working. When I close a terminal window, I get the typical Closing this window will terminate the running processes: watch. message. That ends up terminating my background process, even when using nohup or disown. What could be the problem?

我的code是一个简单的两行

My code is a simple two lines

cmd="nohup watch -n 1 sudo /etc/block.sh > /dev/null"
$cmd & # blocks automatically  

它位于的.bash_profile ,因为我想它,每当我打开一个新的终端启动。

It is located in .bash_profile, because I want it to start up whenever I open a new terminal.

您可以忽略sudo的;我已经找到了一种方法,而无需输入密码来执行sudo命令。

You can ignore the sudo; I've already found a way to execute a sudo command without entering the password.

我使用的Mac OSX。

I am using Mac OSX.

推荐答案

启动子shell和运行的nohup 命令从那里似乎退出时,以避免终端把它扼杀掉

Starting a subshell and running the nohup command from there seems to avoid having Terminal kill it off when exiting.

bash -c "nohup sh -c 'while true; do date; sleep 1; done' &"

不是很优雅,但对我的作品。

Not very elegant, but works for me.

这篇关于关闭终端运行后在后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆