7

In terminal I just type firefox and then Firefox starts, but I can not return to command mode anymore.

How can I come back to command mode?
I have already tried :q or exit, but neither work.

Hastur
  • 2,355
Jimmy
  • 181
  • 1
    If, by command mode, you mean the interactive shell, then no. You have run firefox in such a way so that the terminal will show its output. You can press ^C to send SIGINT to firefox. Doing so will get you back to the interactive shell, but it will kill firefox. Instead, you can run firefox in the background (à la firefox &), and you should already be back to the interactive shell once the process has forked off. – HalosGhost Jul 18 '14 at 21:27
  • 1
    ...firefox & is the right way. If you forget it you can do CRTL-Z to suspend it and after %1 & to execute it in background. – Hastur Jul 18 '14 at 21:54

1 Answers1

9

When you run a program from a shell (e.g. firefox) it will be executed "in foreground". When the program will finish you will have back the possibility to execute another command.

Another way to execute a command is "in background". If you put this symbol & after the command it will be executed asynchronously (in background) and you will have the possibility to execute other commands from the same shell/terminal. Excerpt from man bash:

When bash starts a job asynchronously  (in the background), it prints a line
that looks like:  

          [1] 25647

indicating  that this job is job number 1 and that the process ID of the 
last process in the pipeline associated with this job is 25647.

When you start the second jobs it will answer with [2] NewPid and so on. With the built-in command jobs you will have all the list.

When you run a command "in foreground" and you want to suspend it (not to stop definitively) you can press CTRL+Z. The shell will answer you in a similar way (e.g.)

 [1]+  Stopped                 firefox

To continue the precedent job you can write %1 & (the same number you read from the terminal). You can also do it with bg %1. It will execute the job 1 in background and give you the prompt back, ready to accept new commands.

You may find interesting the article Linux: Start Command In Background

Hastur
  • 2,355
  • This answer would be even better if it stated how to push commands onto the process [1]. E.g. I tell my package manager cabal to first update then after it finishes I want it to install package x. – Owen Dec 29 '21 at 06:36
  • 1
    @Owen, On this site usually One question one answer... but not one answer to rule them all (imagine this phrase said with the voice from the Lord of The Rings when they speak about "The" ring). Assuming a syntax similar to apt, you can always do something like apt update && apt install PackageX where you execute the 1st command (here not in background) and then the second command (apt install PackageX) only if the 1st one exits without errors (&&). To be honest for your example it should be enough ;, but it is better to install only if the update went ok (then &&). – Hastur Dec 29 '21 at 10:41