i don't understand the difference between "top, top&, top &" commands in linux.
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.
Batch mode refers to batch processing, which means automated processing, without human intervention. Batch is the opposite of interactive.
In batch mode, top produces output that's more sensible for collecting to a log file or for parsing (though top isn't really good at producing parseable output even in batch mode). There is no limit on the number of output lines and the output doesn't contain any escape sequences for formatting.
In interactive mode, top produces output intended for human viewing. In particular, it only displays one screenful of data. The output contains some escape sequences for formatting. Top operates in interactive mode even when its output is redirected to a file; only the presence of the -b option matters.
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 textStopped
in the terminal as soon as the backgroundedtop
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:
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, usefg
.In this case, you have two backgrounded
top
processes running. To foreground the first, usefg %1
. To foreground the second, usefg %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 job-control tag.