no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | tech:linux:throttle_process [2015/04/22 11:42] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Throttle background processes ====== | ||
+ | Example to throttle the number of unzips running when a large number of files need to be unzipped | ||
+ | <code bash> | ||
+ | #!/bin/sh | ||
+ | cd / | ||
+ | TARD=/ | ||
+ | LOGF=/ | ||
+ | COUNTER=0 | ||
+ | for z in *.zip; do | ||
+ | LOGFILE=$LOGF/ | ||
+ | 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 | ||
+ | </ | ||