Skip to content

Ctrl+C in R will terminate the child process which is spawned by using "pipe"

3 messages · Rong lI Li, Simon Urbanek, William Dunlap

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

            
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
#
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