Skip to content

Instantly share code, notes, and snippets.

@daniel-thompson
Created November 13, 2017 19:50
Show Gist options
  • Save daniel-thompson/bfe124d8e7374464924d4b86f35235b3 to your computer and use it in GitHub Desktop.
Save daniel-thompson/bfe124d8e7374464924d4b86f35235b3 to your computer and use it in GitHub Desktop.
bash job server
# `parallel <cmd...>` works similarly to `<cmd...> &` but limits the
# maximum job count to prevent over-zealous memory consumption when
# batch processing huge numbers of files.
parallel () {
while [ "$(jobs | wc -l)" -ge $((3 * $(nproc) / 2)) ]
do
wait -n
done
"$@" &
}
for f in $jpegs
do
parallel convert $f --resize ...
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment