Skip to content
Prev 46155 / 63461 Next

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