X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=0.7 required=5.0 tests=AWL,BAYES_20,SARE_HEAD_DATE_LONG1,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Mon, 6 Dec 2010 23:07:01 +0000 (GMT Standard Time) From: Arthur Norman To: cygwin AT cygwin DOT com Subject: Program repeatedly restarts when its console is closed Message-ID: User-Agent: Alpine 2.00 (WNT 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com At the end of this message is a short program. It is linked as a windows-mode executable so when it is launched it does not have a console. It then allocates one and uses it. The expected behaviour is that when I run it a fresh DOS-style console appears and I can type a few chars in and they get echoed. This happens happily. EXCEPT that if before typing in 5 chars I close the console either via its file/close menu or by clicking the little "x" at the right of its title bar and IF I launched the program from cygwin using execv/execve (as the cygwin bash shell does) the application console winow closess but the program is instantly relauched. I see this with both the 32 & 64-bit versions of the non-cygwin compilatets - ie replace x86_64-w64-mingw32-gcc with just "gcc -mno-cygwin" has the same behaviour. If instead of launching the binary via cygwin's execv I launch it direct from a plain old DOS shell then closing the console window causes the program to terminate in the way I expected. It is not clear to me whether this is an issue of the mingw bits not handling things and exiting badly or of the cygwin execv behaving improperly. Eg it I write a very short program that goes basically execv("./bad0",...) and compile that using cygwin but then run that executable from a normal DOS shell I get the hydra-like behaviour where when I cut of a console a fresh one instantly re-grows, even though launching bad0 directly does not suffer that way. So if mingw people can confirm that this is a problem on the cygwin side the issue can be forwarded that way... When I posted this for mingw64 people to comment on the response I got back was "This indicates the problem to be with Cygwin. Have you asked them? I know that Cygwin doesn't have control of the exec-ed "native" program but it may be trapping the signals and causing the primary program to not end so that it reopens the console making it appear to be "restarting"." Many thanks, {I am on Windows 7 64-bit with the x86_64 compiler versions that cygwin installs for me, but I have tried the bad0 executable on a windows 2000 (virtual) machine and observe the same bad effects in the 32-bit version there, so actually this is not just a 64-bit issue and not just a Windows 7 one). Arthur =========================================================== /* * x86_64-w64-mingw32-gcc -mno-cygwin bad0.c \ * -Wl,--subsystem=windows -o bad0 * ./bad0 */ #include #include int main(int argc, char *argv[]) { int i; if (AllocConsole()) { freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); } for (i=0; i<5; i++) { int c = getchar(); printf("char %d is %#x\n", i, c); fflush(stdout); } return 0; } ============================================================= -- 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