On 2/6/07, Alexandru E. Ungur <[EMAIL PROTECTED]> wrote:
>>> sender: "Alex 'CAVE' Cernat" date: "Mon, Feb 05, 2007 at 08:41:57PM
+0200" <<<EOQ
> [..]
> Ce m-ar interesa ar fi niste exemple de cum se face in bash (nu stiu
> daca se poate) [..]
Ceva in genul asta nu ar merge?
=== fork fun in bash ===
#!/bin/bash
# Max 'threads'
MAX=3
function next_worker() {
# Some way to retrieve the unique ID/data/whatever for each worker
echo $RANDOM
}
function do_work() {
local WORKER_ID=$1
echo "Doing work for ${WORKER_ID}..."
sleep $[$RANDOM % 6]
echo "Done for $WORKER_ID"
}
while :; do
if [ `jobs|wc -l` -le $MAX ]; then
do_work `next_worker` &
else
sleep 2
fi
aici cred ca merge si un wait in loc de o bucla while cu sleep, i.e.
for task in whatever
do
do_work $task &
done
wait
iacata ca "Ma indoiesc ca in bash poti sa faci asa ceva." se poate :-P
_______________________________________________
RLUG mailing list
[email protected]
http://lists.lug.ro/mailman/listinfo/rlug