Linux – top, top&, top & commands in linux

background-processlinuxtop

i don't understand the difference between "top, top&, top &" commands in linux. enter image description here

Best Answer

The & character at the end of a command, no matter if it's preceded by a space or not, will start a background process (sometimes also called an asyncrounous process since the shell will not wait for it to terminate before executing the next command).

Running top as a background process makes little sense as it is, by default, an interactive program. This is also why you see the text Stopped in the terminal as soon as the backgrounded top tries to interact with the user (it can't, because it's not connected to the controlling terminal).

On my system, I get a slightly more descriptive message:

[1] + Stopped (tty output) top

meaning "top tried to write something to the terminal, but couldn't, so it's been stopped temporarily".

To move the backgrounded top into the foreground, use fg.


In this case, you have two backgrounded top processes running. To foreground the first, use fg %1. To foreground the second, use fg %2.

The numbers in %1 and %2 are job IDs, or job specifications. These corresponds to the numbers in square brackets displayed when you started the background jobs.


Related:

... and other questions related to the tag.

Related Question