This is the mail archive of the cygwin@sourceware.cygnus.com 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]

execvp returns after exec.....


I have a small piece of test code:

/**********************************************************************  
******************************/
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <errno.h>

void main()
{
   char *args[4], prog[80];
   int ch;
   strcpy (prog, "c:\\mingw32\\projects\\srcbin\\mysleep.exe");
   ch = '7';
   printf( "\n\n" );

   args[0] = prog;
   args[1] = "-s";
   args[2] = "10";
   args[3] = NULL;

   fprintf(stderr, "- Prog is: %s; my pid is %d\n", prog, getpid() );
   fprintf (stderr, "- Sending args:\n1 %s\n2 %s\n3 %s\n4 %s\n", 
args[0], args[1], args[2], args[3]);
      execvp( prog, args );

   /* This point is reached only if exec fails. */
   printf( "\nProcess was not execed. %d\n", errno );
   perror ("Not execd:");
   exit( 0 );
}
/**********************************************************************  
******************************/

mysleep.exe -s 10 will cause mysleep to wait 10 secs before printing a 
message out. What I observe is that as soon as the execvp is done, 
control returns to my DOS prompt and I can continue to run commands as 
if the process was done. 10 secs later I get a message from mysleep. 
The output is shown below (and I noticed that the PID of the execd 
process is different from the original process). Does anyone know why 
this happens and is there a way for me to change the behavior to where 
control does not return until mysleep is done?

------------- Output -------------------------
C:\mingw32\projects\srcbin>tst2


- Prog is: c:\mingw32\projects\srcbin\mysleep.exe; my pid is 391
- Sending args:
1 c:\mingw32\projects\srcbin\mysleep.exe
2 -s
3 10
4 (null)

C:\mingw32\projects\srcbin>dir
 Volume in drive C has no label.
 Volume Serial Number is F079-7ADD

 Directory of C:\mingw32\projects\srcbin

09/26/97  08:20a        <DIR>          .
09/26/97  08:20a        <DIR>          ..
09/26/97  08:17a                 1,437 mysleep.c
09/26/97  08:18a                10,500 mysleep.exe
09/26/97  08:20a                   899 tst2.c
09/26/97  08:20a                10,507 tst2.exe
              13 File(s)         73,807 bytes
                            576,462,336 bytes free

C:\mingw32\projects\srcbin>>> mysleep: pid 260: done sleeping 10 secs

C:\mingw32\projects\srcbin>
---------------------------------- End output 
------------------------


Regards

Deepak Khosla
281-514-9234
DKhosla@compaq.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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