Created
March 25, 2009 09:14
-
-
Save larstobi/85386 to your computer and use it in GitHub Desktop.
BASH parallell jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PID_LIST="" | |
for i in `seq 1 9`; do | |
sleep 3s && echo $? > /tmp/PID_${!} & | |
PID_LIST="${PID_LIST} $!" | |
echo "Started process with pid $!" | |
done | |
wait | |
for pid in ${PID_LIST}; do | |
echo "PID: ${pid} EXIT: $(</tmp/PID_${pid})" | |
rm /tmp/PID_${pid} | |
done | |
# # You can get notification when a child exits: | |
# set -o monitor # enable script job control | |
# trap 'echo "child died"' CHLD | |
#!/bin/bash | |
FILE_COUNT=`ls *.mp3 2> /dev/null |wc -l` | |
if [ ${FILE_COUNT} -gt 0 ]; then | |
FILES=`ls *.mp3` | |
PID_LIST="" | |
PID_DIR=`/usr/bin/mktemp --tmpdir=/tmp --directory nikon-get.XXXXXX` | |
MAX_PROCS=4 | |
CUR_PROCS=0 | |
for file in $FILES; do | |
if [[ ${CUR_PROCS} -ge ${MAX_PROCS} ]] ; then | |
wait; | |
CUR_PROCS=0; | |
fi | |
############# DO SOME COMMAND HERE ############# | |
${HOME}/bin/mp3tag --artist="Dude" ${file} \ | |
&& echo $? > ${PID_DIR}/$! & # This is to store PID in a file. | |
############# END COMMAND ############# | |
CUR_PROCS=$((${CUR_PROCS}+1)) | |
done | |
wait; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment