Rong lI Li
2013-Jul-02 15:46 UTC
[Rd] Ctrl+C in R will terminate the child process which is spawned by using "pipe"
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? 1. I used pipe to spawn one C++ process, which will running in a loop without exiting immediately. z <- pipe("./mytest", open = "r+")> zdescription 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@cn.ibm.com [[alternative HTML version deleted]]
Simon Urbanek
2013-Jul-02 16:13 UTC
[Rd] Ctrl+C in R will terminate the child process which is spawned by using "pipe"
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
William Dunlap
2013-Jul-02 16:16 UTC
[Rd] Ctrl+C in R will terminate the child process which is spawned by using "pipe"
If you are on a Unix-like machine try using the setsid command to run your command in a 'session' of its own. E.g., > z <- pipe("setsid /usr/bin/yes", open="r") > length(readLines(z, n=1e6)) [1] 1000000 > # hit control-C > length(readLines(z, n=1e6)) [1] 1000000 > length(readLines(z, n=1e6)) [1] 1000000 > close(z) as opposed to > z <- pipe("/usr/bin/yes", open="r") > length(readLines(z, n=1e6)) [1] 1000000 > # hit control-C > length(readLines(z, n=1e6)) # this reads what is left in the stdin buffer [1] 34240 > length(readLines(z, n=1e6)) [1] 0 > close(z) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf > Of Rong lI Li > Sent: Tuesday, July 02, 2013 8:46 AM > To: r-devel at r-project.org > Subject: [Rd] Ctrl+C in R will terminate the child process which is spawned by using "pipe" > > > 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? > > 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]]
Rong lI Li
2013-Jul-04 12:07 UTC
[Rd] Ctrl+C in R will terminate the child process which is spawned by using "pipe"
Hi, all, My previous question is: "how to make the child process run happily without being terminated, after hit Ctrl+C in R". For this, I tried both "setsid" and blocking signals in the child process. Both of them can solve this issue. Considering the compatibility between Unix/Linux platform and windows platform, I choose to use block signals in the child process. Thanks again for all your help! ==================== Rong "Jessica", Li Platform Symphony TET, CSTL, IBM Systems &Technology Group, Development Tel:86-10-82451010 Email:ronglli@cn.ibm.com [[alternative HTML version deleted]]
Reasonably Related Threads
- How can C++ read the R object written into socket with saveRDS or save
- How can C++ read the R object written into socket with saveRDS or save
- 2 questions about signal & broken connection in R
- Newb Question : How do I load the Rsymphony Library, and How do I get Symphony Running on my windows Vista?
- {worker} after :end-time worker freaks out