How to keep application running after closing the terminal?

EDIT: This may only work for certain types of terminals. It is best to run one more command of disown after starting your commands like below so the applications are disassociated with the terminal window.


From a terminal window, type in

nohup geany > /dev/null
disown

or

nohup geany >/dev/null &
disown

nohup allows the application to be ran and immune to hangups, so closing the terminal window would have no effect on the application being run. Adding the >/dev/null to the command prevents the creation of a nohup.out in each directory the application is being run from.

From the man page:

NAME
       nohup - run a command immune to hangups, with output to a non-tty

SYNOPSIS
       nohup COMMAND [ARG]...
       nohup OPTION

And

$ disown --help
disown: disown [-h] [-ar] [jobspec ... | pid ...]
    Remove jobs from current shell.
    
    Removes each JOBSPEC argument from the table of active jobs.  Without
    any JOBSPECs, the shell uses its notion of the current job.
    
    Options:
      -a    remove all jobs if JOBSPEC is not supplied
      -h    mark each JOBSPEC so that SIGHUP is not sent to the job if the
            shell receives a SIGHUP
      -r    remove only running jobs
    
    Exit Status:
    Returns success unless an invalid option or JOBSPEC is given.

As an alternative to nohup you could use the shell builtin disown. disown removes jobs from the job list, and when the shell exists, SIGHUP is not sent to that process.

geany &
disown
exit

You can use exec geany & exit (note the exec and ampersand) if you do not need root and pkexec geany & exit if you need root privileges.

Tags:

Command Line