dba7671
#!/bin/sh
dba7671
# Reads filenames on stdin, xz-compresses each in place.
dba7671
# Not optimal for "compress relatively few, large files" scenario!
dba7671
dba7671
# How many xz's to run in parallel:
dba7671
procgroup=""
dba7671
while test "$#" != 0; do
dba7671
	# Get it from -jNUM
dba7671
	N="${1#-j}"
dba7671
	if test "$N" = "$1"; then
dba7671
		# Not -j<something> - warn and ignore
dba7671
		echo "parallel_xz: warning: unrecognized argument: '$1'"
dba7671
	else
dba7671
		procgroup="$N"
dba7671
	fi
dba7671
	shift
dba7671
done
dba7671
dba7671
# If told to use only one cpu:
dba7671
test "$procgroup" || exec xargs -r xz
dba7671
test "$procgroup" = 1 && exec xargs -r xz
dba7671
dba7671
# xz has some startup cost. If files are really small,
dba7671
# this cost might be significant. To combat this,
dba7671
# process several files (in sequence) by each xz process via -n 16:
1469491
exec xargs -r -n 16 -P "$procgroup" xz