Search code examples
bashjob-control

Ran multiple instances of my program in the background at the same time, what do these return signs mean?


I just kicked off a bunch of instances (17) of my program to test them running concurrently. This is what the terminal output looked like near the end.

    [9]   Done                    perl test.pl -a
    [10]   Done                    perl test.pl -a
    [11]   Done                    perl test.pl -a
    [12]   Done                    perl test.pl -a
    [13]   Done                    perl test.pl -a
    [14]   Done                    perl test.pl -a
    [15]   Done                    perl test.pl -a
    [16]-  Done                    perl test.pl -a
    [17]+  Done                    perl test.pl -a

The 17th was the last one. I was wondering, what does the [16]- and [17]+ mean? Just that they were the last two processes to finish?


Solution

  • From §7.1 "Job Control Basics" in the Bash Reference Manual:

    Job number n may be referred to as ‘%n’. The symbols ‘%%’ and ‘%+’ refer to the shell’s notion of the current job, which is the last job stopped while it was in the foreground or started in the background. A single ‘%’ (with no accompanying job specification) also refers to the current job. 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 ‘-’.

    (emphases mine).

    So it's not that they were the last ones to finish, but that they were the last ones to be started in the background.