# Slave-0.0.1

**URL:** <https://www.ruby-forum.com/t/slave-0-0-1/95681>\
**Category:** Ruby\
**Created:** [June 9, 2006, 12:05am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681 "2006-06-09T00:05:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2006, 12:05am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/1 "2006-06-09T00:05:39Z")

</div>

URIS

[http://codeforpeople.com/lib/ruby/slave/](http://codeforpeople.com/lib/ruby/slave/)  
[http://rubyforge.org/frs/?group\_id=1024&release\_id=5631](http://rubyforge.org/frs/?group_id=1024&release_id=5631)

SYNOPSIS

the Slave class forks a process and starts a drb server in the child  
using  
any object as the server. the process is detached so it is not  
required  
(nor possible) to wait on the child pid. a Heartbeat is set up  
between the  
parent and child processes so that the child will exit of the parent  
exits  
for any reason - preventing orphaned slaves from running  
indefinitely. the  
purpose of Slaves is to be able to easily set up a collection of  
objects  
communicating via drb protocols instead of having to use IPC.

typical usage:

```
 obj = AnyClass::new

                                 #
 slave = Slave::new obj # object becomes drb server in 

```

another  
# process

```
 p slave.object # handle on drb object
 p slave.uri # uri of the drb object
 p slave.socket # unix domain socket path for drb 

```

object  
p slave.psname # title shown in ps/top

```
 obj = slave.object

                                 #
 p obj.method # call a method on drb server in 

```

another  
# process

other usage:

set the pulse\_rate used for the Heartbeat

```
 slave = Slave::new MyClass::new, 'pulse_rate' => 10

```

same

```
 Slave::pulse_rate = 10
 slave = Slave::new MyClass::new

```

same

```
 ENV['SLAVE_PULSE_RATE'] = 10
 slave = Slave::new MyClass::new

```

slaves may be configured via the environment, the Slave class, or via  
the ctor  
for object itself. attributes which may be configured include

- socket\_creation\_attempts
- pulse\_rate
- psname
- debug

INSTALL

gem install slave

enjoy.

-a

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2006, 1:49am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/2 "2006-06-09T01:49:47Z")

</div>

Ara,

I am trying to use your package on Windows. I’m running into an issue at  
line 341 of slave.rb:

@pipe.fcntl Fcntl::F\_SETFD, Fcntl::FD\_CLOEXEC

I’m curious what these flags mean and what their equivalent on Windows  
might  
be (if any).

I already solved a couple of issues (well, hacked around them):

1. No fork() on windows. Solved by installing Daniel B.'s  
win32-process  
gem
2. “drbunix” URI fails on non-unix. Solved by passing nil to  
Drb.start\_service (ugly hack, hoping to make it cleaner later)

Thanks for any help!

Justin

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2006, 3:01am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/3 "2006-06-09T03:01:06Z")

</div>

On Fri, 9 Jun 2006, Justin B. wrote:

hi justin-

> I am trying to use your package on Windows. I’m running into an issue at  
> line 341 of slave.rb:
> 
> @pipe.fcntl Fcntl::F\_SETFD, Fcntl::FD\_CLOEXEC
> 
> I’m curious what these flags mean and what their equivalent on Windows might  
> be (if any).

it means that, should the parent do something like

exec ‘another\_program.exe’

the pipe will be closed. it’s important since pids are recycled and  
pipes  
transfered the slave would live on for while - perhaps indefinitely.

of course it’s possible that behaviour is desireable, but then a zombie  
would  
also be created… anyhow, for hacking it’s safe to comment that out.

> I already solved a couple of issues (well, hacked around them):
> 
> 1. No fork() on windows. Solved by installing Daniel B.'s win32-process  
> gem
> 2. “drbunix” URI fails on non-unix. Solved by passing nil to  
> Drb.start\_service (ugly hack, hoping to make it cleaner later)

this could easily be configured - check out how the other stuff is  
configured  
and do something like allow the ENV var ‘SLAVE\_DRB\_PROTOCOL’ to override  
this… perhaps a better option might be

Drb.start\_server ‘drb://localhost.localdomain:0’

note that ‘nil’ here doesn’t work on macs for some reason…

i’m running out the door now, but i’d love to make this work on windows

- just  
for the challenge. maybe dan can lend a hand? 😉

maybe we can work together and make another release that’s portable.  
ping me  
offline if your’re interested.

cheers.

-a

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2006, 3:37am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/4 "2006-06-09T03:37:51Z")

</div>

Ara.T.Howard wrote:

> [http://codeforpeople.com/lib/ruby/slave/](http://codeforpeople.com/lib/ruby/slave/)  
> …  
> the Slave class forks a process and starts a drb server in the child  
> …  
> slave = Slave::new MyClass::new, ‘pulse\_rate’ =\> 10

‘Master’ and ‘Slave’ labels unacceptable.

“Based on the cultural diversity and sensitivity of Los A. County,  
this is not an acceptable identification label.”

[http://www.cnn.com/2003/TECH/ptech/11/26/master.term.reut/](http://www.cnn.com/2003/TECH/ptech/11/26/master.term.reut/)

Enjoy,  
Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2006, 4:42am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/5 "2006-06-09T04:42:33Z")

</div>

Cloexec doesn’t exist on Windows. It would be meaningless anyway,  
because  
there’s no notion of a fork. In effect, everything is cloexec.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2006, 4:56am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/6 "2006-06-09T04:56:24Z")

</div>

On Fri, 9 Jun 2006, Francis C. wrote:

> Cloexec doesn’t exist on Windows. It would be meaningless anyway, because  
> there’s no notion of a fork. In effect, everything is cloexec.

everything on windows is meaningless to me 😉 care to review the code  
and  
suggest a way to make it portable?

cheers.

-a

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 11, 2006, 6:44am UTC](https://www.ruby-forum.com/t/slave-0-0-1/95681/7 "2006-06-11T06:44:44Z")

</div>

On Jun 8, 2006, at 5:58 PM, removed\_email\_address@domain.invalid wrote:

> note that ‘nil’ here doesn’t work on macs for some reason…

IPv6?

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
