Skip to content
Prev 4123 / 15075 Next

R console hangs

On Dec 5, 2007, at 3:45 AM, Robin Hankin wrote:

            
In the above example "yes" is running forever despite the fact that  
its pipe has been closed (look in ps) and R is waiting for yes to quit  
which it doesn't.

The cause is that SIGPIPE is set to be ignored by R, and this behavior  
is inherited by the processes it starts, including the yes process.  
Since yes runs forever and relies on a PIPE signal to stop, it will  
never stop when run from R (save for an explicit SIGINT).

Changing system to something like

   sig_t psh=signal(SIGPIPE, SIG_DFL);
   system(command);
   if (psh != SIG_ERR) signal(SIGPIPE, psh);

fixes the problem. However, I'm not sure whether this has any side- 
effects I'm not aware of - hence CC to R-core: is the above safe? Also  
I don't quite understand why this behavior is not seen on Linux  
despite the fact that SIGPIPE is equally blocked ...

Cheers,
Simon