Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 X-USANET-Auth: 165.212.8.20 AUTO rgetter AT usa DOT net cmsweb07.cms.usa.net Date: Thu, 06 Nov 2003 15:04:39 -0500 From: Rob Getter To: Subject: ctrl-c handling problem with win32 native apps. Mime-Version: 1.0 Message-ID: <148HkFuen2784S07.1068149079@cmsweb07.cms.usa.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id hA6K5AMd023116 I am on a team developing a windows console application, and when I run it under a cygwin shell, the ctrl-c handling does not work properly, but it does when run under cmd or 4nt. What happens is that the application exits almost immediately after ctrl-c is pressed, and the ctrl-c handler does not have time to complete, so the application does not shutdown properly. I have created the following program which demonstrates on my system that a program compiled with cygwin works properly, but the same program compiled with gcc -mno-cygwin exhibits the same behavior I described above, but works correctly in a windows native shell. ************************************ #include #include #ifdef CYGWIN #include #else #include #endif int flag = 0; #ifndef CYGWIN void sleep(int sec) { Sleep(sec*1000); } #endif static void siggy(int signo) { if (signo == SIGINT) { flag = 1; signal(SIGINT, SIG_DFL); } } int main() { if (signal(SIGINT, siggy) == SIG_ERR) { printf("could not set SIGINT\n"); } printf("polling for SIGINT...\n"); while (!flag) { sleep(1); printf("waiting for SIGINT\n"); } printf("SIGINT received\n"); printf("sleeping...\n"); sleep(5); printf("exiting\n"); } ******************************** The #ifdef'd code is to sleep() will work the same in both executables. Compile the program like so: gcc testprog.c -o cygtestprog.exe gcc -mno-cygwin testprog.c -o wintestprog.exe cygtestprog and wintestprog behave the same under a windows shell (cmd or 4nt) but wintestprog exits immediately under bash and zsh while cygtestprog behaves properly. The application actually uses SetConsoleCtrlHandler() instead of signal, but the observed behavior is the same, so the test app demonstrates the problem more simply. Is this a known problem? or perhaps a problem with my setup? Thank you for any help you can offer. rob -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/