Four tasks in parallel... how do I do that?
If you have a copy of xargs
that supports parallel execution with -P
, you can simply do
printf '%s\0' *.png | xargs -0 -I {} -P 4 ./pngout -s0 {} R{}
For other ideas, the Wooledge Bash wiki has a section in the Process Management article describing exactly what you want.
In addition to solutions already proposed, you can create a makefile that describes how to make a compressed file from uncompressed, and use make -j 4
to run 4 jobs in parallel. The problem is that you will need to name compressed and uncompressed files differently, or store them in different directories, else writing a reasonable make rule will be impossible.
If you have GNU Parallel http://www.gnu.org/software/parallel/ installed you can do this:
parallel ./pngout -s0 {} R{} ::: *.png
You can install GNU Parallel simply by:
wget http://git.savannah.gnu.org/cgit/parallel.git/plain/src/parallel
chmod 755 parallel
cp parallel sem
Watch the intro videos for GNU Parallel to learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1