Sending the command(s) spawned by xargs to background
Use the --max-procs
/ -P
option to run xargs targets in the background. From the man page of GNU xargs version 4.2.27:
--max-procs=max-procs, -P max-procs
Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs will run as many processes as possible at a time. Use the -n option with -P; otherwise chances are that only one exec will be done.
(You may want to combine this with -n 1
to makes sure that there is a new process for each file you want to compress)
You could probably make a very quick shellscript to call compress.
#!/bin/sh
# call it 'compbg' and chmod a+x
compress $* &
then
find . -type f -mtime +7 | tee compressedP.list | xargs -I{} compbg {}
Although I think you might be happier using this xargs argument:
-P maxprocs
Parallel mode: run at most maxprocs invocations of utility at once.
This command should find / tee / compress 10 files at a time until its done, as well as returning control immediately to the calling script/shell.
find . -type f -mtime +7 | tee compressedP.list | xargs -I{} -P10 compress {} &
For SunOS you may have a look at GNU Parallel http://www.gnu.org/software/parallel/
find . -type f -mtime +7 | tee compressedP.list | parallel compress
It has the added benefit of not terminating incorrectly if the filename contains ' " or space. Adding -j+0 will make it run one compress per CPU core.