[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Question on exec subprocesses

Rick DeNatale

9/28/2006 11:51:00 PM

On 9/28/06, Phy Prabab <phyprabab@yahoo.com> wrote:
> Folks,
>
> Can someone shed some light on how I can accomplish something similar to this:
>
> exec("foo action")
> exec("foobar action")
> Process.wait
>
> I want to wait on the second process, yet in ruby 184, all processes are waited on (until completion). How can I effectively fork off these process simultaneously and wait for the last one to complete or what would be really nice, is to wait for both of these separate processes to finish.

First of all, exec replaces the current process with an external command.
Also Process.wait (if you got to it, which you wouldn't after exec)
wait's for any child process to terminate.

Now assuming that "foo action" and "foobar action" are ruby
expressions and not external commands I thing you want something like
this:

child_pid1 = fork { foo action }
child_pid2 = fork {foobar action}

child_pid1 and child_pid2 will be the process id's of the respective children.

Now you can do a variety of things as far as waiting for the processes
to end including:

# wait for any child to exit and return it's process id
child_pid = Process.wait

# wait for all children to exit and return an array of the form:
# [[pid1, status1], ...]
status_arrays = Process.wait_all

# wait for any child to exit and return an array containing the child
# processes pid and status
status_array = Process.wait2

# wait for a specific child process
waitpid(child_pid1)

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

1 Answer

simonblack

8/3/2013 2:58:00 AM

0

On Sunday, July 28, 2013 8:25:36 AM UTC-7, TD wrote:
> On Sunday, July 28, 2013 7:57:06 AM UTC-4, Lord Valve wrote:
>
> > ic wrote:
>
> >
>
> >
>
> >
>
> > > http://youtu.be/W...
>
> >
>
> >
>
> >
>
> > "I don't know anything about music.
>
> >
>
> > In my line you don't have to."
>
> >
>
> > - Elvis Presley -
>
>
>
> He told the truth, but one thing for certain. He appreciated jazz (doubt atonal, which is understandable concerning at least himself) and good jazz players. I can attest to that.

Gotta love Elvis, LOL, right on, love his exit in that clip. Great post ic.