8

I am new to Linux and using Terminal. If I open an application within terminal, I noticed that it renders my terminal session to be unusable and I can't enter any more commands.The Terminal session is focused on the task of running the application only. Is there a way to bypass this or do I just have to wait until I end my session with the process.

Kisner
  • 81
  • ...And a bunch of others – Jacob Vlijm Mar 31 '15 at 13:53
  • @JacobVlijm: What is the "canonical" answer to this question, to which all dupes should refer? – krlmlr Mar 31 '15 at 14:38
  • @krlmlr It is one of these subjects that pass by on a regular base (in different variants). I already mentioned http://askubuntu.com/questions/106351/running-programs-in-the-background-from-terminal. A quick search also gives http://askubuntu.com/questions/319843/i-cant-use-the-terminal-while-gedit-command-is-running, http://askubuntu.com/questions/331451/how-do-i-run-an-application-with-arguments-from-the-command-line-without-losing. I also remember an extensive answer on the subject by KasiyA (couldn't find it in a quick search). Looking on StackOverflow, there are many more on the subject. – Jacob Vlijm Mar 31 '15 at 16:46

3 Answers3

8

Use disown command:

gedit & disown

This way launched process is disconnected from the terminal it was launched in.

andrybak
  • 337
  • Is that tha same as nohup gedit & or is there some difference? – Tulains Córdova Mar 31 '15 at 15:58
  • Effect is similar, but when nohup is used, one wouldn't be able to send SIGHUP signal (e.g. using kill command) to the process. Note, however, that process may change it's behavior regarding signals itself.

    From man nohup: "nohup - run a command immune to hangups ...". From man bash: "Before exiting, an interactive shell resends the SIGHUP to all jobs [...] To prevent the shell from sending the signal to a particular job, it should be removed from the jobs table with the disown builtin or marked to not receive SIGHUP using disown -h."

    – andrybak Mar 31 '15 at 18:02
3

There are a number of ways that you can continue working.

If you opened a gnome-terminal via CTRL-ALT-T you can choose File from the top menu bar and then choose to open a new tab or a new terminal window via the menu or with the shortcut keys with SHIFT-CTRL-T or SHIFT-CTRL-N respectively(while gnome-terminal has focus).

If you've opened a terminal session with CTRL-ALT-F1, you can switch to another with CTRL-ALT-F2 through F6.

Another option is to background the task as you launch it by placing an & at the end of the command for example dd if=infile of=outfile &. you can string commands by putting a double ampersand between them. ls /home > dir.file && du /home/Downloads for example.

Of course placing processes in the background requires a way of handling background tasks. the fg PID command allows you to bring a process to the foreground. you can obtain the PID with the jobs command more information on handling background tasks can be found here

you can also use nohup and disown as mentioned in the other good answers here. Differences between these approaches are discussed here

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
  • Note that to background a command, you need to add a single ampersand (&) to the end of it. – terdon Mar 31 '15 at 13:30
1

nohup command & will do the trick. You will get just one message in terminal , hit Enter and continue using terminal as before.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497