Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

bash - Start background process from .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.

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
...

and

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

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?

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

Thanks for help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try replacing "nohup gkrellm &" with this:

screen -S gkrellm -d -U -m gkrellm

This will start a detached screen session running gkrellm, and it won't care about the current shell session. I'm not sure if starting it from .bashrc is the best solution though, it would make more sense to use your window manager's autostart features.

Edit: Not sure if I read the question correctly, are you using KiTTY to connect to a linux host and running gkrell remotely through X forwarding? If that is the case, you obviously can't use window manager features. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...