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

Re: fork within a shell script



On Fri, Aug 23, 2002 at 08:31:40PM -0400, Derrick 'dman' Hudson wrote:
> On Sat, Aug 24, 2002 at 01:51:20AM +0200, Christian Schoenebeck wrote:
> | Hi!
> | 
> | I'm wondering how I can fork within a shell script, or bettr let's say how
> | to parallel launch programs in a script instead of the sequential way.
> | 
> | I tried to use the & character like this:
> | 
> | for INDEX in ${ALIST[*]};
> | 	do commandbla &;
> | done
> | 
> | But that always results in an 'unexpected token' error.
> 
> Try this instead :
> 
> for INDEX in ${ALIST[*]}; do
>     commandbla &
> done
> 
> 
> (leave out the semicolon)


Also, you may find that you need to wait until something is finished
before proceeding further.  When you start a background process, the
shell variable $! is set to the process ID of that background process.
You can then save this in another variable, or wait on this id to
finish by calling wait.

- Chris



Reply to: