Just to add to Markie1006's excellent explanation of shell jobs, the fg and bg commands can accept as arguments the job number as well.
An example you can do right at home in your own shell:
Code:
bill@yogi:~$ sleep 9991 &
[1] 10088
bill@yogi:~$ sleep 9992 &
[2] 10090
bill@yogi:~$ sleep 9993 &
[3] 10092
bill@yogi:~$ jobs
[1] Running sleep 9991 &
[2]- Running sleep 9992 &
[3]+ Running sleep 9993 &
Notice the + and - signs next to the second and third jobs. The + next to the third job means that it is at the top of the job manager queue. The - next to the second job means it's second in that queue. They have those designations now because they were the most recent (+) and most previous (-) jobs started. These are status indicators. The + also refers to a "current" job.
Whenever you invoke the fg or bg command, it will take the job with a + as the argument to the command. Since you have three jobs running, that might not be very convenient should you need to access the first job. In which case you can invoke `fg 1` to foreground the first job. Once you do that, the job gets the + designation and the - designation moves to where the + was.
Code:
bill@yogi:~$ fg 1
sleep 9991
[1]+ Stopped sleep 9991
bill@yogi:~$ jobs
[1]+ Stopped sleep 9991
[2] Running sleep 9992 &
[3]- Running sleep 9993 &
I stopped the job so I could show you the example shown in the jobs output. Follow? It gets even better...
Since a foregrounded job gets precedence there can be only one; thus the fg command can only accept one argument (not positive but I can't get it to accept anything else). The bg command can, however, accept more than one argument. If you go through (using the fg command) and ctrl-z stop all three processes then you can use the bg command to either cycle through the designated queue to background everything again, or you can explicitly set them to the background in one command:
Code:
bill@yogi:~$ jobs
[1] Stopped sleep 9991
[2]- Stopped sleep 9992
[3]+ Stopped sleep 9993
bill@yogi:~$ bg
[3]+ sleep 9993 &
bill@yogi:~$ bg
[2]+ sleep 9992 &
bill@yogi:~$ bg
[1]+ sleep 9991 &
Code:
bill@yogi:~$ bg 1 2 3
[1]+ sleep 9991 &
[2]+ sleep 9992 &
[3]+ sleep 9993 &
bill@yogi:~$ jobs
[1] Running sleep 9991 &
[2]- Running sleep 9992 &
[3]+ Running sleep 9993 &
One thing to note, however. If all three jobs are running, then the last job initially executed will have the + designation and the second-to-last will have the - designation regardless of how you manipulate them. If two are running and one is stopped, then the stopped job will have a + and if two are stopped and one if running then the last stopped job will have the +. Stopped jobs apparently get precedence to the bg and fg commands. That's very confusing but the more you play with it you'll understand it. Here's an example that best illustrates my last paragraph:
Code:
bill@yogi:~$ bg 3 1 2
[3]- sleep 9993 &
[1]- sleep 9991 &
[2]+ sleep 9992 &
bill@yogi:~$ jobs
[1] Running sleep 9991 &
[2]- Running sleep 9992 &
[3]+ Running sleep 9993 &
bill@yogi:~$ fg 2
sleep 9992
[2]+ Stopped sleep 9992
bill@yogi:~$ fg 3
sleep 9993
[3]+ Stopped sleep 9993
bill@yogi:~$ fg 1
sleep 9991
[1]+ Stopped sleep 9991
bill@yogi:~$ jobs
[1]+ Stopped sleep 9991
[2] Stopped sleep 9992
[3]- Stopped sleep 9993
bill@yogi:~$ bg 2
[2] sleep 9992 &
bill@yogi:~$ jobs
[1]+ Stopped sleep 9991
[2] Running sleep 9992 &
[3]- Stopped sleep 9993
The `jobs` command also accepts arguments. If you check the references I included at the end you'll know that there are a few interesting ones. One thing it doesn't really talk about is the ability to use status as the argument.
Code:
bill@yogi:~$ jobs
[1] Stopped sleep 9991
[2]- Stopped sleep 9992
[3]+ Stopped sleep 9993
bill@yogi:~$ jobs + -
[3]+ Stopped sleep 9993
[2]- Stopped sleep 9992
bill@yogi:~$ jobs - +
[2]- Stopped sleep 9992
[3]+ Stopped sleep 9993
bill@yogi:~$ jobs 1
[1] Stopped sleep 9991
bill@yogi:~$ jobs -
[2]- Stopped sleep 9992
Well I hope that answered your question. As far as I know there's no real way to change the priority of a job without stopping one. I'm speculating that job priority is related to process priority and that I don't know too much about... yet.
References:
Code:
bill@yogi:~$ help jobs
jobs: jobs [-lnprs] [jobspec ...] or jobs -x command [args]
Lists the active jobs. The -l option lists process id's in addition
to the normal information; the -p option lists process id's only.
If -n is given, only processes that have changed status since the last
notification are printed. JOBSPEC restricts output to that job. The
-r and -s options restrict output to running and stopped jobs only,
respectively. Without options, the status of all active jobs is
printed. If -x is given, COMMAND is run after all job specifications
that appear in ARGS have been replaced with the process ID of that job's
process group leader.
bill@yogi:~$ help bg
bg: bg [job_spec ...]
Place each JOB_SPEC in the background, as if it had been started with
`&'. If JOB_SPEC is not present, the shell's notion of the current
job is used.
bill@yogi:~$ help fg
fg: fg [job_spec]
Place JOB_SPEC in the foreground, and make it the current job. If
JOB_SPEC is not present, the shell's notion of the current job is
used.