DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 597Bdt5T3577653
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 597Bdt5T3577653
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=mIQIjrB7
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B274E3858C53
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1759837193;
	bh=ct70gdfCOR91u4QQZkmb8NigKfwoQr2uaI6HaEGP95o=;
	h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post:
	 List-Help:List-Subscribe:From:Reply-To:From;
	b=mIQIjrB76Kcj3w5rCGBTqT/U84X3gFaz3PsZowa5tRvBpvbxd8Yl06DolTXrqefin
	 L09ixssqSZtyAadyzrpUmyUTxZx6OAnmhzeRvmTdgljiXqAlrdW3XFsTqy4vtbZUBR
	 /80WcU4zNI4Z6PZqfml/rTkPG3rq3y7H7QOvKzxk=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F34133858CD1
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F34133858CD1
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759837131; cv=none;
 b=fswfyz0Tcsz3WaJ5XK8PhKoLV4DIpsVJB0dU9e+Lq08HoUCZYJbHWS1dvzyv4HpV2P+964simK8GpimUrz5QQQX2GXZsHnmaHM9oW8tfw9Q8h7lOMb+CcnQDfYSt530jLWCWirrI3/CqaOEMagojLdvg5GiAd/BYAXxSO5GYF10=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1759837131; c=relaxed/simple;
 bh=8277RtqUwUNL322td8UShNiU6ZIVmRQ0uLbPEFAqTFQ=;
 h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;
 b=GoEWjCW1yBF3TVzTrAt8sFMDeZ0RpPBYlDGwr3Jk1HpDpeSvxX81wmaaXcOvytia7ND1iYYOIl9e+YIQ6s0tXbNkp5jaF6h3BQppx2TvXastKf7pDa8INqoRzM/vQA9kWnD3p4g6nfiZQYoMhvz2nCmNCOF9giiIAu0wmN1gxBo=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F34133858CD1
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1759837129; x=1760441929;
 h=to:subject:message-id:date:from:mime-version:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=aNxv+wlJPMbTXi+j93B+evf/cyvdMc6RCUBDeVeW3h0=;
 b=SYjH02/7ZUVy9x8JA+x0oQFdlvV/jGEtuscG56Hp4mDskLVonf6sRP2sqEwd6FDhFP
 0Wpbny2tx5Xr9a0MIY4bMcsij4tPwQ5EKSfxNla9om3SmZMAjQZgJ5Ky1/hV+2mbAlNr
 sZ6GMzM0DjXmGAT2YNs5ZxBgYK0naTJLv9TnowSbuEZo8yJDJZMZSlZzLgwmR5la8pug
 l4h0T4Kzq73XxAjpsyT0+zKyw7scxU5zps1C7MTI9Q7stfQdd7Kn7ufcxLp0kyNg1KqO
 A73XpZPajjtZlYuTBMFRw8xeCKTBO+mrVg9LhdibApuwyQRLCo58wY7dt7BOJsWrToj9
 I0qQ==
X-Gm-Message-State: AOJu0YwOdmmi62RYzOtkuCJeGe9db93ASA4tpNKhcmyL6udMZOx4p4P9
 q2sltujbjnGOLhrrt9VzyJbsBBMWo0Cs25CJvwVZlPhO7GVq3jKDgXYRuriw2Esd6/5qnSA0dwY
 mah6MM/epGP5BPbODWuXxkBw6zOWbKh6jvUGL3Yc=
X-Gm-Gg: ASbGncuA40Dq4Qbntz9b9t4gCAA7sKcMYU9/xC/+srglxZngDyasi9WJpGFKsHqRo4h
 8y61kc8q4brearyfmzvSb8zuI/1sq3+70KwyEwj8AIJ1X1hlCx0aUMao/MU7epCtro8xE+1Y13t
 pEPaCdRvwQPQNFZwM2WhJhGIlr05QYWVopes4cOyDx1dgVzLAVuy2I8CbCqSVSbcABnejh9/KBD
 Nn2tCdE/vJ4SarfAnYkV8HOj1ICeS2LzAFAIUiaoA==
X-Google-Smtp-Source: AGHT+IHfCoHUJJarVL52C2J8T73RwxRiZoguL+0ZOHOkvSoeaKJTT1Wlz5FCqGZrHy/mEQwvk3TJIjqRlZDRSUjA7jM=
X-Received: by 2002:a05:6512:6cf:b0:55f:435e:36bd with SMTP id
 2adb3069b0e04-58cb69145a0mr4749551e87.0.1759837128798; Tue, 07 Oct 2025
 04:38:48 -0700 (PDT)
MIME-Version: 1.0
Date: Tue, 7 Oct 2025 12:38:37 +0100
X-Gm-Features: AS18NWBsW7DNp4hxZCqO6QUCkbcQedA4fdkSmw0vQ1fjSrZ70Wv89zmIYQ8qJRQ
Message-ID: <CANgSWMMdLZa=aN79XgJwYSHyX87bDzcmjEjWTeQL54aybS934A@mail.gmail.com>
Subject: job control in cygwin bash
To: cygwin@cygwin.com
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Vadym Krevs via Cygwin <cygwin@cygwin.com>
Reply-To: Vadym Krevs <vkrevs@gmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

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 <stdio.h>
    #include <process.h>

    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@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@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@host /cygdrive/c/builds
    $ ./a &
    [1] 15909

    user@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?

Many thanks in advance,
Vadym

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
