0

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

8

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.

3

top& and top & do the same thing.

They'll both run top as a background task (which in case of top is not very useful)

In your screenshot this is shown by [1] 4679 and you can get the process into the foreground by using fg 1.

You can read more on that Topic here

0

First of all top& and top & are same thing as & is used to run processes in background. The only difference between top and top& or top & is simple top will be running as process on your screen and top& or top & will run as background process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.