24

I am new to Ubuntu. I have used Sublime Text. I have realized that after I open Sublime Text from the Terminal, if I close the terminal the application keeps running. The same isn't true for other applications like geany.

After I open the application from terminal, when I close the terminal the application also closes. I have tried &exit like geany &exit. But this isn't what I am looking for.

How can I keep geany running even after I close it?

muru
  • 197,895
  • 55
  • 485
  • 740
odbhut.shei.chhele
  • 395
  • 2
  • 3
  • 11

3 Answers3

32

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.

Terrance
  • 41,612
  • 7
  • 124
  • 183
  • @eddard.stark You're very welcome! =) – Terrance Jul 19 '15 at 00:02
  • 2
    Maybe nohup geany > /dev/null or nohup geany > /dev/null &, to prevent the creation of a nohup.out file in the current working directory each time the command is run – kos Jul 19 '15 at 01:26
  • No problem, upvoted already (by the way in general feel free to not even bother crediting me in the post for such a little enhancement!) – kos Jul 19 '15 at 01:33
  • 1
    @kos OK, I removed it. But thanks again for the reminder. There are times that I forget some of the simple things to stop the log output creation. I really look forward to good suggestions from others. =) – Terrance Jul 19 '15 at 01:36
  • 1
    Often the run output is helpful/important for monitoring status or keeping track of what was done. It this case you would want to use something like nohup run1_cmd.sh > run1.out. – Steven C. Howell Jul 19 '15 at 03:53
13

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
mniip
  • 405
  • 2
  • 6
4

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.

Erkin Alp Güney
  • 488
  • 4
  • 15