[R-SIG-Mac] R console hangs

Simon Urbanek simon.urbanek at r-project.org
Wed Dec 5 15:39:07 CET 2007


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

> MacOSX10.4.11; R-2.6.1 (downloaded the dmg yesterday).
>
>
> I am having difficulty with system().  In my case the unix command
> produces
> a single very very long line and my toy example appears to
> hang R:
>
>
> string <- "yes | sed 10q | tr '\n' ' ' "
> a <- system(string,intern=TRUE)
>
> in the R Console  R seems to hang and
> I need to force-quit.
>
>
> Things are better on a terminal but I still need to type control-C
> to suspend the system() command.
>
>
> Anyone?
>

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



More information about the R-SIG-Mac mailing list