When there are several jobs, you address the one you need by its number, written with a percent sign.
fg %2 brings job 2 to the foreground, and bg %1 continues job 1 in the background. Without a number, fg and bg take the current job, the one jobs marks with +. The - sign marks the previous one.
fg and bg understand a number without % too, but other commands take such a number for a PID. kill, which sends signals to processes, takes kill 1 to mean process 1, which is systemd, and is refused, while kill %1 ends job 1. That is why you always write a job number with %.
Which command continues the stopped job in the background?
$ jobs -l
[1]- 2034 Running sleep 600 &
[2]+ 2041 Stopped sleep 700
-
A job number goes after
%, and 2041 is a PID. There is no job 2041, sobgprintsno such job. -
Job 1 is already Running. The stopped one is job 2:
[2]+ … Stopped. -
fgcontinues job 2 in the foreground and takes the terminal.bgis what continues it in the background.
Job 2 is the stopped one, and bg %2 continues it in the background. The % goes before a job number; a PID is written without it.
Key points
-
A job number is written with
%: without it,killand other commands take the number for a PID. -
fg %Nandbg %Ncontinue job N in the foreground or in the background; without a number they take the current job, marked+.