Throttle background processes
Example to throttle the number of unzips running when a large number of files need to be unzipped
#!/bin/sh cd /data/somefolder/rzips TARD=/data/somefolder/anotherfolder LOGF=/data/somefolder/unziplog COUNTER=0 for z in *.zip; do LOGFILE=$LOGF/${z}.log CNTUNZIP=`ps -ef|grep -c unzip` while [ $CNTUNZIP -gt 51 ]; do sleep 1 CNTUNZIP=`ps -ef|grep -c unzip` done let COUNTER=COUNTER+1 echo "#: $COUNTER - Unzipping $z" nohup unzip $z -x LOG* -d $TARD > $LOGFILE 2>&1 & done