delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/12/25/16:02:49

X-Spam-Check-By: sourceware.org
Message-ID: <45903C5C.2030904@scytek.de>
Date: Mon, 25 Dec 2006 16:02:20 -0500
From: Volker Quetschke <quetschke AT scytek DOT de>
User-Agent: Thunderbird 1.5.0.9 (Windows/20061207)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: spawn doesn't return for non-cygwin programs (and also is unbreakable)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------enigD4DBFEE08B05D3AC8B207816
Content-Type: multipart/mixed;
 boundary="------------050808090503020502060509"

This is a multi-part message in MIME format.
--------------050808090503020502060509
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi!

I recently tripped over the following problem: If a non-cygwin
program gets started by cygwin's spawnvp() the spawn doesn't return
until the started program returns.

To illustrate the problem just compile attached the attached
breaktestwin.c file as a cygwin executable

$ gcc breaktestwin.c -o breaktestwin.exe

and the attached wsleep.c as a native W32 executable

$ gcc -mno-cygwin wsleep.c -o wsleep.exe

and start breaktestwin.exe.

$ ./breaktestwin.exe

You will see that the "Started child  ..." message will not
appear until wsleep finishes.

This problem is actually known since 2001 but I thought it's
OK to mention it again. See:
<http://www.cygwin.com/ml/cygwin/2001-03/msg00068.html>

Another point that did not get mentioned AFAIK is that the
program is not interruptible by CTRL-c while spawnvp() is
waiting for it's "child". (Only true if CYGWIN=3Dtty or when
rxvt or something that handles tty's correctly is used.)

Try hitting CTRL-c while breaktestwin.exe is running from
a tty enable shell. The SIGINT will be handled after the
spawnvp() finishes.


Regards

   Volker


--=20
PGP/GPG key  (ID: 0x9F8A785D)  available  from  wwwkeys.de.pgp.net
key-fingerprint 550D F17E B082 A3E9 F913  9E53 3D35 C9BA 9F8A 785D

--------------050808090503020502060509
Content-Type: text/plain;
 name="breaktestwin.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="breaktestwin.c"

#include <stdio.h>
#include <process.h>
#include <errno.h>
#include <signal.h>
#include <sys/wait.h>

void sigproc(int);
void quitproc(int);

int
main(void)
{
  pid_t pid1, wid;
  int status;

  char *cmnd[] =3D {"wsleep", "10", (char *)0 };

  signal(SIGINT, sigproc);
  signal(SIGQUIT, quitproc);=20

  pid1 =3D spawnvp(_P_NOWAIT, cmnd[0], (const char**) cmnd);
  fflush(stdout);
  if(pid1 =3D=3D -1) {
    fprintf(stderr,"%s : %s\n", cmnd[0], strerror(errno));
  }
  fprintf(stderr, "Started child pid: %d from parent %d\n", pid1, getpid());

  do {
     wid =3D wait(&status);
     fprintf(stderr, "wait returned: %d\n", wid);
  } while( wid !=3D pid1 );

  fprintf(stderr, "pid: %d wid: %d\nDone\n", pid1, wid);
}

void sigproc(int a) {
   fprintf(stderr, "you have pressed ctrl-c \n");
}
=20
void quitproc(int a) {
   fprintf(stderr, "ctrl-\\ pressed to quit\n");
//   exit(0); /* normal exit status */
}

--------------050808090503020502060509
Content-Type: text/plain;
 name="wsleep.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="wsleep.c"

// Compile with MinGW
#include <stdio.h>
#include <windows.h>
=20
int main(int argc, char *argv[])
{  int wait;

   if( argc !=3D 2 ) {
      printf("wsleep takes exactly one argument!");
      return 1;
   }

   wait =3D abs(atoi(argv[1]));
   printf("Waiting %d sec ... ", wait);
   fflush (stdout);
   Sleep(1000*wait);
   printf("done\n");
   fflush (stdout);
=20=20=20
   return 0;
}


--------------050808090503020502060509--

--------------enigD4DBFEE08B05D3AC8B207816
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MinGW)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFkDxhPTXJup+KeF0RAnXgAJ9rb2TacxWd2/6J0m2SHqb/Gyyb4gCdHdan
xZDUcJ8OQyWpsxxowHb4eNw=
=vPy4
-----END PGP SIGNATURE-----

--------------enigD4DBFEE08B05D3AC8B207816--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019