Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to fork child in "non persistent" way?

Received: by 10.58.35.2 with SMTP id d2mr3247102vej.0.1343890871472;
        Thu, 02 Aug 2012 00:01:11 -0700 (PDT)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.52.88.68 with SMTP id be4ls1886017vdb.3.gmail; Thu, 02 Aug
 2012 00:00:53 -0700 (PDT)
Received: by 10.52.21.235 with SMTP id y11mr1975862vde.4.1343890853086;
        Thu, 02 Aug 2012 00:00:53 -0700 (PDT)
Date: Thu, 2 Aug 2012 00:00:52 -0700 (PDT)
From: Mariusz Nowak <mari...@medikoo.com>
To: nodejs@googlegroups.com
Message-Id: <0cc97c64-3cee-46fa-a54b-d2c76ddb1b20@googlegroups.com>
In-Reply-To: <12bab960-fd4d-477b-8d31-ce1ad5a8adeb@googlegroups.com>
References: <5f48b9ca-5912-4ed7-96ce-335b5ca98f71@googlegroups.com>
 <12bab960-fd4d-477b-8d31-ce1ad5a8adeb@googlegroups.com>
Subject: Re: How to fork child in "non persistent" way?
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_642_27428156.1343890852734"

------=_Part_642_27428156.1343890852734
Content-Type: multipart/alternative; 
	boundary="----=_Part_643_14244946.1343890852734"

------=_Part_643_14244946.1343890852734
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

@Bert What I want to achieve is to be able to setup communication bridge 
with other process, but without blocking exit of main process.

Following code will keep process running forever:

var child = require('child_process').fork('./child.js');
child.on('message', function () {
// Process message'
});
child.unref();

It would be good to have some option to make it work similar way to the way 
watchers work with 'persistent' option set to false.
Following code will exit immediately, even though we've initialized 
watcher, attached listener to it and didn't remove it:

var watch = require('fs').watch(__dirname, { persistent: false }, function 
(event) {
  // Process event
});

I wonder if similar setup would be possible with process communication.

-- 
Mariusz Nowak
http://github.com/medikoo
http://twitter.com/medikoo



On Thursday, August 2, 2012 12:59:54 AM UTC+2, Bert Belder wrote:
>
> On Friday, July 27, 2012 6:00:19 PM UTC+2, Mariusz Nowak wrote:
>>
>> I'd like to create fork (via child_process.fork) and make both master and 
>> child exit after all tasks in master process are done
>
>
> If you're using node 0.8, you can do this:
>
> var cp = fork("foo.js")
> cp.unref();
>
> This will effectively "kill" the child process when the master exits, so 
> you may want to install a SIGHUP handler in your child process. 
>  
> - Bert
>

------=_Part_643_14244946.1343890852734
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

@Bert What I want to achieve is to be able to setup communication bridge wi=
th other process, but without blocking exit of main process.<div><br></div>=
<div>Following code will keep process running forever:</div><div><br></div>=
<div><div>var child =3D require('child_process').fork('./child.js');</div><=
div>child.on('message', function () {</div><div><span class=3D"Apple-tab-sp=
an" style=3D"white-space:pre">=09</span>// Process message'</div><div>});</=
div><div>child.unref();</div><div><br></div><div>It would be good to have s=
ome option to make it work similar way to the way watchers work with 'persi=
stent' option set to false.</div><div>Following code will exit&nbsp;immedia=
tely, even though we've initialized watcher, attached listener to it and di=
dn't remove it:<br></div><div><br></div><div><div>var watch =3D require('fs=
').watch(__dirname, { persistent: false }, function (event) {</div><div>&nb=
sp; // Process event</div><div>});</div></div><div><br></div><div>I wonder =
if similar setup would be possible with process communication.</div><div><b=
r></div><div>--&nbsp;<br>Mariusz Nowak</div><div>http://github.com/medikoo<=
/div><div>http://twitter.com/medikoo</div><div><br></div><div><br><div><br>=
On Thursday, August 2, 2012 12:59:54 AM UTC+2, Bert Belder wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;">On Friday, July 27, 2012 6:00:19 PM UTC+=
2, Mariusz Nowak wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;=
margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">I'd like to =
create fork (via child_process.fork) and make both master and child exit af=
ter all tasks in master process are done</blockquote><div><br>If you're usi=
ng node 0.8, you can do this:<br><br>var cp =3D fork("foo.js")<br>cp.unref(=
);<br><br>This will effectively "kill" the child process when the master ex=
its, so you may want to install a SIGHUP handler in your child process. <br=
></div><div>&nbsp;<br>- Bert<br></div></blockquote></div></div></div>
------=_Part_643_14244946.1343890852734--

------=_Part_642_27428156.1343890852734--