从开始的.bashrc后台进程 [英] Start background process from .bashrc

查看:162
本文介绍了从开始的.bashrc后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这可能是一个愚蠢的问题,但即使挖计算器的地盘我解决不了几个小时并彻底谷歌。

I realize that this might be a stupid issue but I can't solve it for hours even if digged stackoverflow site and google throughly.

下面是.bashrc中开始的gkrellm基地code一次我登录到壳

Here is the base code in .bashrc to start gkrellm once I am logged into shell

if ps ax | grep -v grep | grep gkrellm > /dev/null
then
    echo "gkrellm is already running"
else
    command gkrellm &
fi

我已经习惯了尝试

I already used to try

...
else
    nohup gkrellm &
fi
...

...
else
    gkrellm
    $GK_PID=`pidof gkrellm`
    disown -h $GK_PID
fi
...

的gkrellm正确把为背景的工作,我可以使用shell(如预期)。但我仍然有退出的gkrellm一次我preSS CTRL-C即使我开始从同一个shell其他应用程序。如何从收盘CTRL-C preSS做我prevent的gkrellm?

gkrellm is properly put as background job and I can use shell (as expected). BUT I still have gkrellm exiting once I press Ctrl-c even if I start other apps from that same shell. How do I prevent gkrellm from closing on Ctrl-c press?

以防万一。我使用所谓的KITTY腻子克隆,但认为这不是它的问题。

Just in case. I am using PuTTY clone called KiTTY but believe that's not it's issue.

感谢您的帮助!

推荐答案

使用的庆典的(不认&安培; >的/ dev / null的)结果
你需要运行在BG(的gkrellm和放大器; )的应用程序,然后不认

using bash (disown and &>/dev/null)
you need to run the app in the bg (gkrellm &) and then disown it

if ps -C gkrellm -o user | grep "$LOGNAME" &>/dev/null 
then echo "gkrellm is already running"
else gkrellm & disown
fi

如果您想更便携和使用的 POSIX SH 的结果
你将需要使用的nohup 的coreutils 的一部分,POSIX)结果
而且它的背景( CMD的nohup&安培; )结果
您还希望使用的 .profile文件 的而不是 的.bashrc

if you want to be more portable and use posix sh
you will need to use nohup (part of coreutils and POSIX)
and also background it (nohup cmd &)
you'd also use .profile instead of .bashrc

if ps -C gkrellm -o user | grep "$LOGNAME" 2>/dev/null 1>&2
then echo "gkrellm is already running"
else nohup gkrellm &
fi


其他方法将包括 - 为@Pontus回答 - 使用工具,如 dtach 屏幕 TMUX ,其中命令是在一个独立的环境中执行。


other approaches would include - as @Pontus answered - using tools like dtach, screen or tmux, where the command is executed in a detached environment.

由庞的:结果
  它会更有意义,用你的窗口管理器的自动启动功能。

by Pontus:
it would make more sense to use your window manager's autostart features

确实:)作为AFAIK 的gkrellm 是GUI应用程序,最好是自动启动的,或者使用的 的.xinitrc 的(如果你的登录管理器支持的话),或者你的窗口管理器的自动启动设施。

indeed :) as afaik gkrellm is a GUI app, it's better to autostart it, either using .xinitrc (if your login manager supports it), or your window manager's autostart facilities.

这篇关于从开始的.bashrc后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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