DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5985tS5o4108177 Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 5985tS5o4108177 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=srPCXf6j X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 009113857706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1759902925; bh=cdQWRTGb8rnh4TTjpQTg+yC1WcpbibWiOY9f/lcT10w=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=srPCXf6j0sT6hwZNzVhyNo7svm/oQUpucr/vyJOQ9b+lwIV4soRVTHEguccNFnbLf kYdRS+lLE56BfvSDg73JzfOHxiJzf3h7nweonwwBf4MLOWc4nVWZ65rL3Ns6lQ/odm W3lXcYBqy0S5ENi/j/FnTJtYAdri028x1KioOeK4= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0EA53858C83 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A0EA53858C83 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759902860; cv=none; b=EV7V1T160Dpwfu+7cQtddGZNJiTRECHuqurqCLm6U0aRUxiyFV6aNWBlU6PdRkyKKKnHHKR114h3Kxfjxn6/cYVb9ymgWgvh/WT9IbL1pffk0yfhHR8C83uk5y89O6DFBuuSDRhzONGTnndtRIwbO7MLyu6Zym4YPVdhWVOvh1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759902860; c=relaxed/simple; bh=puxtx24Y1HqkjegC7DfulWEbju5EZr6JxCqpw2ivcN8=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=UoLpqFwSycCy7dZ0s77XIDkpon+5aLToT/MmOWTmu409xTw6HUSxz3zkPiXTprCKeuEj1E4vXXQXKbYc4ZbTdguoYBI0mVkAspFuaJg32K666rmBCbnOum2/mxK6spLUTHRH6wRgcFhaSagXiG88EEYj75dMQkgD6zCmtDLMGaM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0EA53858C83 Message-ID: <76ed6af0-34f2-43e3-893f-f33bc36d7876@maxrnd.com> Date: Tue, 7 Oct 2025 22:54:23 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: job control in cygwin bash To: cygwin AT cygwin DOT com References: Content-Language: en-US In-Reply-To: X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mark Geisert via Cygwin Reply-To: Mark Geisert Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" Hi Vadym, On 10/7/2025 4:38 AM, Vadym Krevs via Cygwin wrote: > Hi. > > I've a question regarding job control in cygwin bash. > > Below is a simple program that prints out the process id of itself. > > C:\builds>cat a.c > #include > #include > > int main(int argc, char ** argv) > { > printf("pid=%d\n", _getpid()); > return 0; > } > > Compiling and running it in foreground from cygwin bash works as expected: > > user AT host /cygdrive/c/builds > $ cl a.c > Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35217 for x86 > Copyright (C) Microsoft Corporation. All rights reserved. > > a.c > Microsoft (R) Incremental Linker Version 14.44.35217.0 > Copyright (C) Microsoft Corporation. All rights reserved. > > /out:a.exe > a.obj > > user AT host /cygdrive/c/builds > $ ./a > pid=2352 > > > However, if I start it in background and attempt to get back the pid > of the started process via $!, the result is not what one would > expect. The actual process pid printed out from my program differs > from what cygwin bash thinks is "process ID of the job most recently > placed into the background". > > user AT host /cygdrive/c/builds > $ ./a & > [1] 15909 > > user AT host /cygdrive/c/builds > $ pid=27008 > echo $! > 15909 > [1]+ Done ./a > > > So my question is - is this a cygwin bash quirk (i.e. the fact that $! > is not the pid of the started process) caused by how fork/process > startup is implemented in cygwin? I have tried reading > https://cygwin.com/cygwin-ug-net/highlights.html#ov-hi-process but > could not see anything relevant aside from "Job control works as > expected in shells that support it." in the Signals section. Is there > any way to get the actual process pid? You are using cl to create the executable, and doing so means it results in a native Windows program, not a Cygwin program. Running ldd.exe on your executable will show the Cygwin DLL is not associated. If you instead use gcc to create the executable, this testcase works correctly. Try 'gcc a.c', assuming you have gcc installed (via Cygwin Setup Program). You will also have to change "" to "