changeset 376:dd7632f3000c

Add "--fork 3" option to avoid overwhelming the system with parallel builds.
author Rob Landley <rob@landley.net>
date Sat, 02 Aug 2008 17:18:58 -0500
parents faa38267c038
children 00bb2dbe5ec7
files forkbomb.sh
diffstat 1 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/forkbomb.sh	Sat Aug 02 16:17:28 2008 -0500
+++ b/forkbomb.sh	Sat Aug 02 17:18:58 2008 -0500
@@ -5,6 +5,18 @@
 #  With --nofork, it build them sequentially
 #  With --watch, it displays output from an existing parallel build
 
+function wait4background()
+{
+  # Wait for background task to finish
+  while [ $(jobs | wc -l) -ge $1 ]
+  do
+    sleep 1
+    # Without this next line, bash never notices a change in the number of jobs.
+    # Bug noticed in Ubuntu 7.04
+    jobs > /dev/null
+  done
+}
+
 # Build and package one architecture.
 
 function buildarch()
@@ -68,7 +80,6 @@
       export WRAPPY_LOGDIR=`pwd`/build/cmdlines-host
     fi
 
-
     # Build sequentially.
 
     if [ "$1" == "--nofork" ]
@@ -79,14 +90,20 @@
 
     elif [ "$1" == "--fork" ]
     then
-      (buildarch $i > out-$i.txt 2>&1 &)&
+      if [ -z "$2" ]
+      then
+        (buildarch $i > out-$i.txt 2>&1 &)&
+      else
+        (buildarch $i 2>&1 | tee out-$i.txt)&
+         wait4background $2
+      fi
 
     # Didn't understand command line arguments, dump help.
 
     else
-      echo "Usage: forkbomb.sh [--fork] [--nofork] [--watch] [--stat]"
+      echo "Usage: forkbomb.sh [--fork [N]] [--nofork] [--watch] [--stat]"
       echo -e "\t--nofork  Build all targets one after another."
-      echo -e "\t--fork    Build all targets in parallel (needs lots of RAM)."
+      echo -e "\t--fork    Build N targets in parallel (omit for all, needs lots of RAM)."
       echo -e "\t--watch   Restart monitor for --nofork."
       echo -e "\t--stat    Grep logfiles for success/failure after build."
       exit 1