Keep a program running in terminal

So I am well aware of nohup and suffixing commands with & to ensure that they go into the background.

However if I run a graphical application - sometimes using neither seems to do the job. So what can I prefix a program/command with to ensure that it keeps running after the terminal is closed?


Solution 1:

If you want the application to keep running when you close the terminal window you should do:

nohup chromium-browser &

You need both the nohup and the &.

  • nohup means keep this process/command running after the shell closes.
  • & means put this process/command in the background so it dose not block the shell (so you can use it for something else.

Solution 2:

when running a program in the background via the & operator it's still attached to your session and can be controlled with fg, bg, jobs and disown.

I also had some problems with nohup but disown might be the thing you're looking for.

When you run a program in background it has a job id:

gedit &
[1] 5647

That number in brackets [] is the interesting one. To detatch it from your session run disown %n with that number. For the above example:

disown %1

Now you can safely exit the terminal and the process will not be terminated.