Question
What are the meaning of the +
, -
and signs that precedes
Done
when a background process ends?
Examples of interest
Code 1
(sleep 4s; echo first)& (sleep 2s; echo second)& (sleep 1s; echo third)& [1] Done ( sleep 4s; echo first ) [2]- Done ( sleep 2s; echo second ) [3]+ Done ( sleep 1s; echo third )
Code 2
(echo first)& (echo second)& (echo third)& [1]+ Done ( echo first ) [2]+ Done ( echo second ) [3]+ Done ( echo third )
Starting Processes You can start a background process by appending an ampersand character ( & ) to the end of your commands.
Press 'CTRL+Z' which will suspend the current foreground job. Execute bg to make that command to execute in background.
To bring a process running in the background to the foreground, use the fg command followed by the job id. To put in the background again, press CTRL + Z followed by the bg command.
So here is my understanding of it:
1- Job flagged or having a +
is the one that was sent to the background last.
2- Job flagged or having a -
was sent to the background second last.
3- Other background jobs are not flagged.
Here is an example I just ran on my system
$bash: /singh/test1 & [1] 9223 $bash: /singh/test2 & [2] 9226 $bash: /singh/test3 & [3] 9234 $bash: /singh/test4 & [4] 9237 $bash: jobs [1] Running /singh/test & [2] Running /singh/test2 & [3]- Running /singh/test3 & [4]+ Running /singh/test4 &
I could see from man bash
:
There are a number of ways to refer to a job in the shell. The character % introduces a job specification (jobspec). Job number n may be referred to as %n. A job may also be referred to using a prefix of the name used to start it, or using a substring that appears in its command line. For example, %ce refers to a stopped ce job. If a prefix matches more than one job, bash reports an error. Using %?ce, on the other hand, refers to any job containing the string ce in its command line. If the substring matches more than one job, bash reports an error. 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. 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 -. A single % (with no accompanying job specification) also refers to the current job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With