How can spawning subprocesses affect buffering?


I am writing a system, where there are a few small, slave ruby scripts
doing something, spawned by master one.

I encountered propably a bug, and I don’t know, how to solve it, so
please give me some help…

Please consider following script:

require ‘glib2’
require ‘dbus’

bus = DBus::SessionBus.instance
service = bus.request_service(“dummy.test”)

class DummyDBUS < DBus::Object
dbus_interface “dummy.Test” do
dbus_method :Shutdown do

dbus_method :Spawn do
system("/bin/sh -c ‘while [ 1 ]; do echo . >> /tmp/dot; sleep 1;
done &’")

$mainloop =

dbus_object = “Application”
service.export dbus_object


The idea is that I spawn a some subprocesses after receiving a command
via DBus. Later they communicate via DBus after slave subprocesses had
performed their tasks.

Unfortunately, Shutdown() command does not work if you previously
spawn any subprocesses using Spawn() command. It kills the master
process, but DBus does not release service name until it

I’ve check that it does not matter if they are spawned like

system("/bin/sh -c ‘while [ 1 ]; do echo . >> /tmp/dot; sleep 1; done


exec(“while [ 1 ]; do echo . >> /tmp/dot; sleep 1; done &”) if

or any other way to daemonize subprocess (I’ve tried also

So the first test case is:

  1. Spawn master script mentioned above.
  2. Call Shutdown() method via DBus.
  3. Works perfectly - master process is killed and removed from DBus’
    service list.

Second test case is:

  1. Spawn master script mentioned above.
  2. Call Spawn() method via DBus.
  3. Check, for sure, if subprocess works (tailf /tmp/dot) and if it’s
    separated from master process (e.g. pstree)
  4. Call Shutdown() method via DBus.
  5. Bug! Master process gets killed (mainloop is stopped) but service
    name is not released in DBus until subprocess is killed.


It seems that some DBus messages are waiting until subprocess is
killed - it’s easy to see with dbus-monitor. But how it’s possible
that spawning a subprocess causes buffering those data? Is it a ruby
internal bug? Maybe ruby-dbus bug? dbus itself?

PS. I’ve checked that also without calling bus.glibize, with normal
loop - the same effect.
PS2. I use ubuntu 10.04, ruby 1.8.7 (2010-01-10 patchlevel 249),
libdbus-ruby 0.4.0, libglib2-ruby1.8 0.19.3-1ubuntu3

I appreciate any help or directions,

I also found that master application behavior is different when you
run it via strace but I am not so proficient to interpret that data…

thank you in advance,

That was a bug in ruby-dbus, resolution is here