[TAG] [2 cent Tips] backgrounding the last stopped job without knowing its job ID

Ben Okopnik ben at linuxgazette.net
Mon Feb 22 17:52:41 MSK 2010


On Mon, Feb 22, 2010 at 04:14:09PM +0700, Mulyadi Santosa wrote:
> For most people, to send a job to background after stopping a task,
> he/she will take a note the job ID and then invoke "bg" command
> appropriately like below:
> 
> $ (while (true); do yes  > /dev/null ; done)
> ^Z
> [2]+  Stopped                 ( while ( true ); do
>     yes > /dev/null;
> done )
> 
> $ bg %2
> [2]+ ( while ( true ); do
>     yes > /dev/null;
> done ) &
> 
> Can we omit the job ID? Yes, we can. Simply replace the above "bg %2"
> with "bg %%". It will refer to the last stopped job ID. This way,
> command typing mistake could be avoided too.

What's wrong with a simple 'bg'? The default, when you don't specify an
argument, is the current job.

In my experience, specifying an arg to 'bg' or 'fg' is unnecessary 99%
of the time - but that may just be the way that I use the job system,
since I rarely have more than one thing backgrounded at any one time.
The only place where I find '%%' useful is when it's coupled with
'kill': sometimes, a process that's not amenable to being stopped with
'Ctrl-C' will respond to a 'Ctrl-Z', after which it can be killed off
with 'kill %%'.


-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *





More information about the TAG mailing list