5

Programs like Skype and Tixati can just be called from the terminal without adding an & at the end of their call. Why is this not the case with Firefox. I am just curious as to what programs I need to add the & option to.

2
  • I doubt there's a way to know which programs need &, except trial and error Commented Jun 14, 2015 at 10:28
  • In addition firefox works well, & is to run commands in background
    – Ron
    Commented Jun 14, 2015 at 10:28

3 Answers 3

13

This depends entirely on how the software was written, often also depending on the intent with it.

Most bash (= shell, terminal) utilities are meant to be used "synchronously", with these the execution is meant to produce a result; which might be required for the following commands in a script or manual procedure - if the utility (program, software) detaches and leaves you at the prompt immediately you will not know when or if the result is available.

Skype is not normally used as a command line "utility" but rather a tool to handle communication (phone or whatever). And then it is quite handy if it does not block the terminal, if launched from there.

Detaching from the terminal:
https://superuser.com/questions/178587/how-do-i-detach-a-process-from-terminal-entirely

9

All programs can be called without &. The & is completely optional. All it does is send the process to the background so you can continue using your terminal.

Without it, if you launch a process from the terminal, you will need to wait until that process finishes (or is closed) before being able to continue using your terminal. Therefore, one often runs programs as command & to send them to the background and keep working in the same terminal.

For more on the various shell operators like & and what they do, see here.

3
  • Yeah but like the previous answer said, the program does not need to be sent to the background if it is detached from the terminal.
    – SDG
    Commented Jun 14, 2015 at 10:51
  • 1
    @SharanDuggirala adding a & (or Ctrl+Z and bg) or detaching, using at, nohup, or disown, all have the same superficial effect: they return your terminal to you by running the program in the background. Each approach has different benefits but none are required and all send the process to the background.
    – terdon
    Commented Jun 14, 2015 at 10:57
  • But thanks anyways, I was looking for the operators to use in a terminal
    – SDG
    Commented Jun 14, 2015 at 11:41
3

It is very simple for a program to put itself in the background. The code used to do so could be as simple as this:

if (fork() > 0) _exit(0);

But doing so by default would introduce a few disadvantages. For example you could no longer wrap the program in a script which does something upon the program terminating. And writing output to the terminal from a background process could end up looking quite messy, terminal output from background processes can be disabled but then the background process will be frozen once it tries to produce output.

In my experience Skype and Firefox do not put themselves in the background. They do something different though.

When you start one of these programs they will check if there is already a running instance of the program. If there is a running instance the new instance will send a message to the running instance with the parameter you just gave it, and then quit.

The effect of that is that the already running instance does something, and you get your prompt back.

1
  • 3
    +1. Also, you can usually tell these programs not to look for other instances of themselves, e.g. with skype --secondary or firefox --new-instance. If you do that, without using &, they should always block the terminal until you quit them. Commented Jun 15, 2015 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .