[bash script] running functions "at same time"

This is a discussion on [bash script] running functions "at same time" within the Slackware forums, part of the Help category; Hi, I have a bash script with several functions. I need to run them "in a parallel way" like a "threads", I mean I don't want to wait to finish ...

Go Back   Unix Linux Forum > Unix > Linux > Help > Slackware

FixUnix.com - Unix Linux Forums

Unix Content Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-22-2008, 04:09 PM
Default [bash script] running functions "at same time"

Hi,

I have a bash script with several functions.
I need to run them "in a parallel way" like a "threads", I mean I
don't want to wait to finish executing each before continuing to the
next one in the script.
BTW, I need to run them on a single script so I cannot extract them
and make new scripts for every function.

For the following example:

#!/bin/bash
function one()
function two()
function three()
#launching functions
one
two
trhee
#end

I want to execute function one and continue with the others, so one
should be running while function two is executing as well, same for
function three.

Possible? How can i do that?

Thanks as always,
Jaisol
Reply With Quote
  #2  
Old 08-22-2008, 04:41 PM
Default Re: [bash script] running functions "at same time"

jaisol wrote:
> Hi,
>
> I have a bash script with several functions.
> I need to run them "in a parallel way" like a "threads", I mean I
> don't want to wait to finish executing each before continuing to the
> next one in the script.
> BTW, I need to run them on a single script so I cannot extract them
> and make new scripts for every function.
>
> For the following example:
>
> #!/bin/bash
> function one()
> function two()
> function three()
> #launching functions
> one
> two
> trhee
> #end
>
> I want to execute function one and continue with the others, so one
> should be running while function two is executing as well, same for
> function three.
>
> Possible? How can i do that?
>
> Thanks as always,
> Jaisol


Depends, do the have side-effects? As in modifying variables from the
main script? If not just put & at the end like any normal program.
Bash will start each one in a sub-shell. If they depend on side-effects
you'll have to be more inventive.

Jerry
Reply With Quote
  #3  
Old 08-22-2008, 04:50 PM
Default Re: [bash script] running functions "at same time"

On Fri, 22 Aug 2008 13:09:59 -0700 (PDT), jaisol wrote:

>Hi,
>
>I have a bash script with several functions.
>I need to run them "in a parallel way" like a "threads", I mean I
>don't want to wait to finish executing each before continuing to the
>next one in the script.
>BTW, I need to run them on a single script so I cannot extract them
>and make new scripts for every function.
>
>For the following example:
>
>#!/bin/bash
> function one()
> function two()
> function three()
>#launching functions
>one
>two
>trhee
>#end
>
>I want to execute function one and continue with the others, so one
>should be running while function two is executing as well, same for
>function three.
>
>Possible? How can i do that?


Of course it's possible, wrong group, try comp.newbie.homework.help

Grant.
--
http://bugsplatter.id.au/
Reply With Quote
  #4  
Old 08-22-2008, 05:00 PM
Default Re: [bash script] running functions "at same time"

On Fri, 22 Aug 2008 13:09:59 -0700, jaisol wrote:

> I have a bash script with several functions. I need to run them "in a



Sure ya do. Looks like another day's homework assignment to me. Weren't
you just here asking for homework help a day or two ago?

Bugger off, schoolboy.


--
"Ubuntu" -- an African word, meaning "Slackware is too hard for me".
The Usenet Improvement Project: http://improve-usenet.org

Reply With Quote
  #5  
Old 08-22-2008, 05:59 PM
Default Re: [bash script] running functions "at same time"

On Fri, 22 Aug 2008 13:09:59 -0700, jaisol sprout:

> Hi,
>
> I have a bash script with several functions. I need to run them "in a
> parallel way" like a "threads", I mean I don't want to wait to finish
> executing each before continuing to the next one in the script.
> BTW, I need to run them on a single script so I cannot extract them and
> make new scripts for every function.


Seems your coach is on the level.

>
> For the following example:
>
> #!/bin/bash
> function one()
> function two()
> function three()
> #launching functions
> one
> two
> trhee
> #end


Ah, there was a trap in that one, you're lucky having been asking here
instead of shell or process related groups, so you're now safe as far
as the said trap was the revealing heart. Mind your ``script'' (whatever)
*will* have to respect the typos that your coach creatively enough
inserted in the stencils you just realized were to be answered in the
morrow. Example given (and that's a special feature in this group too
to give you the entire unadulterated full expressions of any usual
shortening, e-g: e-g., kat onoma), so, e-g: the ``function three''
**MUST** respect the "trhee" output, per request.

the rest is easier, as you'll discover below in a full
disclosure.

>
> I want to execute function one and continue with the others, so one
> should be running while function two is executing as well, same for
> function three.
>
> Possible? How can i do that?
>
> Thanks as always,
> Jaisol


Note: when read, do not forget to follow the 'SEE ALSO' hint
$ man make

(or, maybe, if your coach and/or your class is 101)
$ man -k builtins | grep bg
Reply With Quote
Reply

Thread Tools


All times are GMT -5. The time now is 11:15 AM.

In an effort to better serve ads to our visitors, cookies are used on Fixunix.com. For more information, check out our Privacy Policy.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Ad Management by RedTyger