IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

HOWTOs

Search Howtos :Match :

11.6. Stopped Jobs Count

Torben Fjerdingstad () wrote to tell me that he often stops jobs and then forgets about them. He uses his prompt to remind himself of stopped jobs. Apparently this is fairly popular, because as of Bash 2.04, there is a standard escape sequence for jobs managed by the shell:

[giles at zinfandel]$ export PS1='\W[\j]\$ '
giles[0]$ man ls &
[1] 31899
giles[1]$ xman &
[2] 31907

[1]+  Stopped                 man ls
giles[2]$ jobs
[1]+  Stopped                 man ls
[2]-  Running                 xman &
giles[2]$

Note that this shows both stopped and running jobs. At the console, you probably want the complete count, but in an xterm you're probably only interested in the ones that are stopped. To display only these, you could use something like the following:

[giles at zinfandel]$ function stoppedjobs {
-- jobs -s | wc -l | sed -e "s/ //g"
-- }
[giles at zinfandel]$ export PS1='\W[`stoppedjobs`]\$ '
giles[0]$ jobs
giles[0]$ man ls &
[1] 32212

[1]+  Stopped                 man ls
giles[0]$ man X &
[2] 32225

[2]+  Stopped                 man X
giles[2]$ jobs
[1]-  Stopped                 man ls
[2]+  Stopped                 man X
giles[2]$ xman &
[3] 32246
giles[2]$ sleep 300 &
[4] 32255
giles[2]$ jobs
[1]-  Stopped                 man ls
[2]+  Stopped                 man X
[3]   Running                 xman &
[4]   Running                 sleep 300 &

This doesn't always show the stopped job in the prompt that follows immediately after the command is executed - it probably depends on whether the job is launched and put in the background before jobs is run.

Note

There is a known bug in Bash 2.02 that causes the jobs command (a shell builtin) to return nothing to a pipe. If you try the above under Bash 2.02, you will always get a "0" back regardless of how many jobs you have stopped. This problem is fixed in 2.03.

Relative speed: 'jobs -s | wc -l | sed -e "s/ //g" ' takes about 0.24 seconds on an unloaded 486SX25.

Search Howtos :Match :
Inkscape 0.47
Vector graphic editor for SVG
DeleGate 9.9.6-pre5
Proxy server which runs on multiple platforms
Nano 2.1.99pre2
Emulate Pico while also offering a few enhancements.
My Money 2.0.49
Personal financial software
Linux Kernel 2.6 2.6.32-rc8
Linux Kernel
GCstar 1.5.0
Personal collections manager
ImageMagick 6.5.7.9
ImageMagick image processing studio
BibleTime 2.4
Bible study software for Linux / KDE
Tellico 2.1.1
Collection manager for books, music, videos, and bibliographies
Totem 2.28.4
Movie player for Gnome
Free IT Magazines, White Papers, eBooks, and more !
Oracle Magazine

Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.

Vulnerability Management for Dummies

Get all the Facts and See How to Implement a Successful Vulnerability Management Program.

Website Magazine

Has tapped premier talent in the Internet industry for our content and each and every issue will contain practical advice and insights for website owners.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info