X-Spam-Check-By: sourceware.org Message-ID: <001701c6f681$3b2ee160$125110ac@sheffpc> From: "Papasha" To: Subject: Strange fork/exec bug, two processes instead of one are created Date: Mon, 23 Oct 2006 12:57:12 +0400 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="koi8-r"; reply-type=original Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook Express 6.00.2900.2869 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 Hello, everyone, I have a problem using fork/exec, I have a program that launches other program: //spawner.exe #include #include 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 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 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/