简体   繁体   中英

running programs via bash like daemons

Usually I run GUI programs (like libreoffice) just in a terminal, but it means that terminal has to be open while running the app.

How can I let the GUI program continue to run even if I close my terminal?

You want the bash command nohup , which disconnects a process from the terminal, so that it keeps running even if the terminal closes. Use it to run 'nautilus' like this:

nohup nautilus

As you will see, it warns that any stdout from nautilus is saved in a file called nohup.out. If you don't care about the stdout from your GUI app, and don't want to create these nohup.out files, you can redirect stdout to /dev/null. If you do that, nohup saves stderr instead. So you need to redirect both:

nohup nautilus >/dev/null 2>&1

Also, for reasons I don't understand, this is now a blocking call (ie you don't get your terminal prompt back.) So you need to run this in the background:

nohup nautilus >/dev/null 2>&1 &

I've created a Bash function in my .bashrc so that I don't need to type all the above:

nh () 
{ 
    nohup "$@" > /dev/null 2>&1 &
}

Then I can go:

nh nautilus

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM