Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > background child process

Reply
Thread Tools

background child process

 
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-02-2004

How can one start a background child process in a platform independent
manner (i.e., no fork)?

With 'system "something&"', the process is started in the background,
but it is not a child, so I can't wait for it to finish:

$ ruby -e 'system "sleep 5&"; Process.wait'
-e:1:in `wait': No child processes (Errno::ECHILD)
from -e:1

Anyway, I don't know if the 'system "something&"' construct even works
on windows (I'm not near a windows box today, or I'd test it).

Can I do this with pipes? How will I know when the child has exited or died?

I'm reluctant to use pipes because I don't care about stdin/stdout and
don't want to worry about whether win32 support is ok. I don't need
pipes for commuication, since I'm communicating among processes by
writing and reading locked files. Aside from that, all I need to know
from the child is when it is done. (That's the only reason I wanted it
to be a child in the first place, so that I could use Process.wait or
Process.waitpid on it.)

Thanks for any suggestions....



 
Reply With Quote
 
 
 
 
nobu.nokada@softhome.net
Guest
Posts: n/a
 
      01-05-2004
Hi,

At Sat, 3 Jan 2004 07:32:51 +0900,
Joel VanderWerf wrote:
> How can one start a background child process in a platform independent
> manner (i.e., no fork)?


I agree it should be there and kind of feel I've suggested it a
couple times.

> Anyway, I don't know if the 'system "something&"' construct even works
> on windows (I'm not near a windows box today, or I'd test it).


No.

> Can I do this with pipes? How will I know when the child has exited or died?


$ ruby -e 'f = IO.popen("sleep 5"); p Process.waitpid(f.pid); p $?'
14425
#<Process::Status: pid=14425,exited(0)>

> I'm reluctant to use pipes because I don't care about stdin/stdout and
> don't want to worry about whether win32 support is ok. I don't need
> pipes for commuication, since I'm communicating among processes by
> writing and reading locked files. Aside from that, all I need to know
> from the child is when it is done. (That's the only reason I wanted it
> to be a child in the first place, so that I could use Process.wait or
> Process.waitpid on it.)


IO.popen works on also Windows.

--
Nobu Nakada


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pexpect on windows - child process of another child process - quickquestion Z W Python 0 03-09-2013 10:00 PM
a simple program to illustrate that child process does not shareresources with parent process sree.harsha.sn@gmail.com C Programming 4 11-09-2008 03:59 AM
Child process wait father process excute some code then begin execute empriser C Programming 1 03-06-2007 02:24 AM
Proc::Background killing parent process when child dies Paul Clements Perl Misc 2 02-11-2004 01:49 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57