Re: Threading ??? Shell Scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



sos@xxxxxxxx (Steve Siegfried) writes:
> I'm attaching a script (waaay at the bottom), "DISPATCH", which manages
> up to N simultaneous jobs.

IMHO a better (and easier) approach would be to use xargs because it does
exactly what your long script does (I think, I didn't review carefully I
admit):

echo {1..19} | xargs -n 3 -P 3 echo

I used -n because you had 3 args in your example; -P limits the number of
concurrent processes.

A far better example that actually shows the proc limit would be with the
following script in place of the echo command:

#!/bin/bash
echo "pid: $$ ($(date)) $@"
sleep 2


Here's the result:
pid: 14729 (Tue Jun 27 23:30:51 CEST 2006) 4 5 6
pid: 14732 (Tue Jun 27 23:30:51 CEST 2006) 7 8 9
pid: 14727 (Tue Jun 27 23:30:51 CEST 2006) 1 2 3
pid: 14736 (Tue Jun 27 23:30:53 CEST 2006) 10 11 12
pid: 14739 (Tue Jun 27 23:30:53 CEST 2006) 13 14 15
pid: 14742 (Tue Jun 27 23:30:53 CEST 2006) 16 17 18
pid: 14745 (Tue Jun 27 23:30:55 CEST 2006) 19

-- 
Mathieu Chouquet-Stringer


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux