# Background child process

**URL:** <https://rubytalk.org/t/background-child-process/9542>\
**Category:** ruby-talk\
**Created:** [2 January 2004 22:32 UTC](https://rubytalk.org/t/background-child-process/9542 "2004-01-02T22:32:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [2 January 2004 22:32 UTC](https://rubytalk.org/t/background-child-process/9542/1 "2004-01-02T22:32:51Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [5 January 2004 10:51 UTC](https://rubytalk.org/t/background-child-process/9542/2 "2004-01-05T10:51:03Z")

</div>

Hi,

> 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.

> **···**
>
> At Sat, 3 Jan 2004 07:32:51 +0900, Joel VanderWerf wrote:
> 
> –  
> Nobu Nakada
