From simon.urbanek at r-project.org  Tue Jul  2 18:13:23 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 2 Jul 2013 12:13:23 -0400
Subject: [Rd] Ctrl+C in R will terminate the child process which is
	spawned by using "pipe"
In-Reply-To: <OF918D6FB5.0BE55AA5-ON48257B9C.005569B6-48257B9C.0056AE15@cn.ibm.com>
References: <OF918D6FB5.0BE55AA5-ON48257B9C.005569B6-48257B9C.0056AE15@cn.ibm.com>
Message-ID: <E22341A8-ED18-48C8-9870-2FC39EC94EFB@r-project.org>


On Jul 2, 2013, at 11:46 AM, Rong lI Li wrote:

> 
> Hi, all,
> 
> I pressed Ctrl+C in R process, and found that the child process which was
> spawned by using "pipe" is terminated due to this.
> Are there any way to work around it, so that the child process can run
> happily without being terminated? Or can we block the signal for the child
> process?
> 

Yes, simply handle the INT signal in your C++ process and do what you deem appropriate (which does include the option of doing nothing / ignoring).

Other option is to do a double-fork ( fork -> if (fork()) exit) so you disassociate the child from the parent group or to possibly use setsid(), both as to not share the terminal with the parent.

Cheers,
Simon


> 1. I used pipe to spawn one C++ process, which will running in a loop
> without exiting immediately.
> 
> z <- pipe("./mytest", open = "r+")
>> z
> description       class        mode        text      opened    can read
> "./mytest"      "pipe"        "r+"      "text"    "opened"       "yes"
>  can write
>       "no"
> 
> 2. When I press "Ctrl+C" in the current R shell, I found the forked child
> process was also terminated. Are there any way to work around it?
> 
> =====================
> 
> Rong "Jessica", Li (????)
> Platform Symphony TET, CSTL, IBM Systems &Technology Group, Development
> Tel:86-10-82451010  Email:ronglli at cn.ibm.com
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Ctrl+C in R will terminate the child process which is spawned by using "pipe"
Simon Urbanek