Strange fork/exec bug, two processes instead of one are created

Papasha papasha_papovich@mail.ru
Mon Oct 23 10:23:00 GMT 2006


Hello, everyone, I have a problem using fork/exec, I have a program that
launches other program:
//spawner.exe
#include <unistd.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
 pid_t pid = 0;

 if (argc < 2)
 {
  fprintf(stderr, "Usage: spawner executable [arguments]\n");
  return -1;
 }

 pid = fork();
 if (pid == 0)
 {
  execv(*(argv + 1), argv + 1);
 }

 sleep(10);

 return 0;
}

I use it to launch a program compiled using MSVC++ 2005:
//testproj.exe
#include <windows.h>

int main(int argc, char *argv[])
{
 Sleep(10000);
 return 0;
}

So, I'm using first program like this:
./spawner.exe testproj.exe

It starts, everything is ok, but in windows TaskMan I see something like
this:
spawner.exe
spawner.exe
testproj.exe

I have 2 copies of spawner.exe running, It seemed to me so, but after I ran
"ps -W" under cygwin I got:

     PID     PPID    PGID     WINPID  TTY  UID    STIME COMMAND
     2576    2928    2576       3260  con 1003 12:06:07 .../spawner
     2424    2576    2576       3472  con 1003 12:06:07 .../testproj

     3472       0       0       3472    ?    0 12:06:07 
C:\cygwin\...\testproj.exe (where did it come from ???)

It looks like second spawner.exe is not actually a spawner.exe, but another
testproj.exe. Note that first testproj and second testproj have the same
WINPID, but different PIDs and the PID of second testproj = WINPID of first
testproj.

After that I've created another program testproj_cyg.exe similar to
testproj.exe but compiled it with cygwin:
//testproj_cyg.exe
#include <unistd.h>

int main(int argc, char* argv[])
{
 sleep(10);
 return 0;
}

And ran:
./spawner.exe testproj_cyg.exe

And everything was ok, I had one copy of spawner.exe and one copy of
testproj_cyg.exe

So, why does this happen, why there's a second testproj.exe in memory ?
It's compiled with MSVC++ 2005, is that a problem for cygwin's fork/exec ?
why ? 


--
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/



More information about the Cygwin mailing list