mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-26 07:57:58 +00:00
A (crappy) example of sem usage.
This commit is contained in:
parent
0fbd1b2653
commit
8dcde6b058
|
@ -1,10 +1,3 @@
|
||||||
Bug: seq 1 10 | stdout parallel --eta echo
|
|
||||||
|
|
||||||
# Examples of sem
|
|
||||||
|
|
||||||
find . -execdir sem -j100 'sleep 4; echo {}' \; ; sem --wait
|
|
||||||
|
|
||||||
|
|
||||||
fex syntax for splitting fields
|
fex syntax for splitting fields
|
||||||
http://www.semicomplete.com/projects/fex/
|
http://www.semicomplete.com/projects/fex/
|
||||||
sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1}
|
sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1}
|
||||||
|
|
33
src/parallel
33
src/parallel
|
@ -1298,6 +1298,39 @@ As there is not a I<command> the option B<--command> is default
|
||||||
because the jobs needs to be evaluated by the shell.
|
because the jobs needs to be evaluated by the shell.
|
||||||
|
|
||||||
|
|
||||||
|
=head1 EXAMPLE: Working as mutex and counting semaphore
|
||||||
|
|
||||||
|
The command B<sem> is an alias for B<parallel --semaphore>.
|
||||||
|
|
||||||
|
A counting semaphore will allow a given number of jobs to be started
|
||||||
|
in the background. When the number of jobs are running in the
|
||||||
|
background, GNU B<sem> will wait for one of these to complete before
|
||||||
|
starting another command. B<sem --wait> will wait for all jobs to
|
||||||
|
complete.
|
||||||
|
|
||||||
|
Run 10 jobs in parallel in the background:
|
||||||
|
|
||||||
|
for i in `ls *.log` ; do
|
||||||
|
echo $i
|
||||||
|
sem -j10 gzip $i ";" echo done
|
||||||
|
done
|
||||||
|
sem --wait
|
||||||
|
|
||||||
|
A mutex is a counting semaphore allowing only one job to run. This
|
||||||
|
will edit the file I<myfile> and prepends the file with lines with the
|
||||||
|
numbers 1 to 3.
|
||||||
|
|
||||||
|
seq 1 3 | parallel sem sed -i -e 'i{}' myfile
|
||||||
|
|
||||||
|
As I<myfile> can be very big it is important only one process edits
|
||||||
|
the file at the same time.
|
||||||
|
|
||||||
|
Name the semaphore to have multiple different semaphores active at the
|
||||||
|
same time:
|
||||||
|
|
||||||
|
seq 1 3 | parallel sem --id mymutex sed -i -e 'i{}' myfile
|
||||||
|
|
||||||
|
|
||||||
=head1 QUOTING
|
=head1 QUOTING
|
||||||
|
|
||||||
For more advanced use quoting may be an issue. The following will
|
For more advanced use quoting may be an issue. The following will
|
||||||
|
|
Loading…
Reference in a new issue