This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem redirecting stderr to pipe in subprocess



Ken Brown-6 wrote:
> 
> On 10/9/2011 4:10 PM, jan.kolar wrote:
>>
>>
>> Ken Brown-6 wrote:
>>>
>>> The attached STC arose from my attempt to understand the problem
>>> discussed starting in
>>>
>>>     http://cygwin.com/ml/cygwin/2011-09/msg00405.html .
>>>
>>> I'm starting a new thread because there appears to be a Cygwin problem
>>> having nothing to do with emacs.
>>>
>>> The STC creates a pipe and then runs `bash -ic ls' in a subprocess, with
>>> both stdout and stderr sent to the pipe.  The parent process reads from
>>> the pipe and echoes it to the terminal.
>>>
>>> On Linux, I first get the error messages (presumably expected)
>>>
>>> bash: cannot set terminal process group (-1): Invalid argument
>>> bash: no job control in this shell
>>>
>>> followed by the directory listing.  On Cygwin, the bash process produces
>>> no output but is simply stopped, and I have to kill it from another
>>> terminal before the main program will exit.  This happens both with
>>> cygwin-1.7.9 and the latest snapshot.  Here are a few comments:
>>>
>>> 1. The problem disappears if I don't send bash's stderr to the pipe.
>>>
>>> 2. The problem also disappears if I replace -ic by -c in the call to
>>> bash, presumably because there's nothing sent to stderr in that case.
>>>
>>> 3. The problem disappears if I don't use a pipe but just have the bash
>>> subprocess write to the terminal, even if I redirect bash's stderr to
>>> stdout.
>>>
>>> Ken
>>>
>>
>>
>> * Does your program work when compiled by gcc-4 (as opposed to gcc-3) ?
>>
>> --
>>
>> Because I also spot some problem with it, if gcc-3 is used:
>>
>> # correct with gcc-4
>> $ gcc-4 STC.c&&  ./a.exe
>> ls: cannot access neeeee: No such file or directory
>> .bashrc*
>>
>> # custom cygwin1.dll warning with gcc-3 :
>> $ gcc-3 STC.c&&  ./a.exe
>> #####   Ooops, first in forkee and it is not dll:init; where=dcrt0.cc
>> dll_crt0_1()   pozde - je po linked dll::init iwhere=90
>> ls: cannot access neeeee: No such file or directory
>> .bashrc*
>>
>> I think I've have never seen the message (its my debug message); if you
>> confirm your program makes difference between gcc-3 and gcc-4, I will
>> have
>> find out what it means.
>> (Probably it is like unexpected ordering of DLL's or ordering of their
>> initialization.)
> 
> I always use gcc-4.  I've just recompiled with gcc-3, and the results 
> are the same.
> 
> Ken
> 
> 
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> 
> 
> 

Thank you very much.
I hoped to get something repeatable here, but this way I cannot help.
Meanwhile, I only got two crashed processes in 20000 cases. (I have modified
1.7.9-1 here).


Note: there is timeout of 300s in a number of places, so it is possible you
see an error message only after 5 minutes of waiting.
   fork.cc:#define FORK_WAIT_TIMEOUT (300 * 1000)     /* 300 seconds */

Otherwise, what you can do is to look at the output of  
  strace a.exe.

What I can do is this:
pstree -p
gdb a.exe <PID>           and         gdb ls <PID>

and try to find out by commands
info threads,  thread <n>, bt,  up, down,  list.

The two cases I found seems ot be just 'random' crashes unrelated to pipe.

However, this also shows that most random dead pipes i get (seldom, but
there are some)
are perhaps caused by hanged processes without relation to pipe
implementation.

In one case, a.exe was consuming processor time and did not know how to exit
(I still hold in dbg, has 18+ threads):
#3  0x610cd8a5 in remove_proc (ci=0) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/sigproc.cc:1023
1022          while (!procs[nprocs].waiter_ready)              happened to
be infinite loop
1023            yield ();
(gdb) bt
#0  0x776870b4 in ntdll!LdrFindResourceEx_U () from
/cygdrive/c/Windows/SYSTEM32/ntdll.dll
#1  0x77686ab4 in ntdll!__iscsymf () from
/cygdrive/c/Windows/SYSTEM32/ntdll.dll
#2  0x75a4d383 in SwitchToThread () from
/cygdrive/c/Windows/system32/KERNELBASE.dll
#3  0x610cd8a5 in remove_proc (ci=0) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/sigproc.cc:1023
#4  0x610ce178 in proc_subproc (what=<optimized out>, val=1) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/sigproc.cc:330
#5  0x610ce407 in proc_terminate () at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/sigproc.cc:374
#6  0x610cf8c1 in sigproc_terminate (es=ES_FINAL) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/sigproc.cc:487
#7  0x610a2bc8 in pinfo::exit (this=0x611807a0, n=65280) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/pinfo.cc:189
#8  0x61005380 in do_exit (status=65280) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/dcrt0.cc:1186
#9  0x610054a6 in _exit (n=<optimized out>) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/dcrt0.cc:1208
#10 0x611224e4 in exit (code=-1) at
/usr/src/cygwin-1.7.9-1-merge/newlib/libc/stdlib/exit.c:65
#11 0x610050cb in cygwin_exit (n=-1) at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/dcrt0.cc:1202
#12 0x6100718d in _cygwin_exit_return () at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/dcrt0.cc:1019
#13 0x61004cb6 in _cygtls::call2 (this=0x22ce64, func=0x61006a30
<dll_crt0_1(void*)>, arg=0x0, buf=0x22cda4)
    at /usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/cygtls.cc:69
#14 0x61004d5b in _cygtls::call (func=0x61006a30 <dll_crt0_1(void*)>,
arg=0x0)
    at /usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/cygtls.cc:62
#15 0x6100699f in _dll_crt0@0 () at
/usr/src/cygwin-1.7.9-1-merge/winsup/cygwin/dcrt0.cc:1039
#16 0x004012e2 in cygwin_crt0 ()
#17 0x00401015 in mainCRTStartup ()


The other case was confused and could be some memory corruption.
-- 
View this message in context: http://old.nabble.com/Problem-redirecting-stderr-to-pipe-in-subprocess-tp32616089p32621088.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]