Background a certain number of jobs in bash using job control


/ Published in: Bash
Save to your folder(s)

this works even if you call this script in the background... awesome


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. for i in {1..10}; do
  3. while [ `jobs | wc -l` -ge 4 ] ; do
  4. sleep 1
  5. done
  6. (echo $i ; sleep 3 ) &
  7. done

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.