19

Run a job in the background

$ command &

When it's done, the terminal prints

[n]+    command

or

[n]-    command

So sometimes it's a plus and other times it's a minus following [n].

What does plus/minus mean?

17

They are to distinguish between current and previous job; the last job and the second last job for more than two jobs, with + for the last and - for the second last one.

From man bash:

The previous job may be referenced using %-. If there is only a single job, %+ and %- can both be used to refer to that job. In output pertaining to jobs (e.g., the output of the jobs command), the current job is always flagged with a +, and the previous job with a -.

Example:

$ sleep 5 &
[1] 21795

$ sleep 5 &
[2] 21796

$ sleep 5 &
[3] 21797

$ sleep 5 &
[4] 21798

$ jobs
[1]   Running                 sleep 5 &
[2]   Running                 sleep 5 &
[3]-  Running                 sleep 5 &
[4]+  Running                 sleep 5 &

$ 
[1]   Done                    sleep 5
[2]   Done                    sleep 5
[3]-  Done                    sleep 5
[4]+  Done                    sleep 5
2

I'm guessing you are referring to when you check jobs via $jobs. However, as you probably know already, n denotes the job #. The [n] + denotes the final job that was called. [n] - denotes the second to last job that is called.

For example:

chris@chris-VirtualBox:~$ sleep 30 &
[1] 904
chris@chris-VirtualBox:~$ sleep 50 &
[2] 972
chris@chris-VirtualBox:~$ jobs
[1]-  Running                 sleep 30 &
[2]+  Running                 sleep 50 &

That is why, in this case, our sleep 50 & is last: [2]+ and sleep 30 & is second to last: [1]-

  • Your description of the situation is unclear and the system does not predict which job will end first. – Julie Pelletier Aug 30 '16 at 14:32
  • I see what you mean, I will emphasize the main point – Klamz Aug 30 '16 at 14:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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