delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/10/08/03:32:12

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5987WCPh4147452
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 5987WCPh4147452
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=Ec/QJanW
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0458F3857357
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1759908730;
bh=vwJOEK886F81bWB577bG7tL22a7cHwE4D8x0d+yzvIs=;
h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=Ec/QJanWpA1dHyAZDnw213LREzIW94fDQh1+TssxWv/LHlqftQH1Z01fDJU7kunwU
MXkpbxYZXlnTJtPvhTAQxoZurOdAZEsCXDwoCtL9OlP7D1y5v8Q+CFum9+QT5Nk7jg
6FDo6zLxqRIW3khIgKfQFvUMij4/BYKYQqF4+qF0=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86F4D3858C83
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 86F4D3858C83
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1759908693; cv=none;
b=flplR6trwA6EZeVz1Bf70NnpiCAo1EwnRHz3CMWV0ZcTCeLs3/0u3REpFZDr1QNlbowx4U7wL0XQW+L9MKpJD0sXZnrA6di/DQII3hFTzKjnJje3LAEE4DVvs7V2W0k9tWKj3CzjbgFbGy1OTDfwFv7XarJOJk/w9n3F8p1R84U=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1759908693; c=relaxed/simple;
bh=O6iyWx/LexdxLZlSEq3lJr86XtNMurwF906dtf7iohU=;
h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To;
b=Vo6YhWHI+O0Y2K8n+37fxMcI3CIAGn7r/kgQZFhczOtmLOyOro/U+bP8LEIkq5UvoumErJuIOUQ0oMAUi3PFtelfD1R80YAg6JpYVeete7uAwjuWzcBiXjQQItcgb3/+0b4p3NV5ZaerrZXoR5kwH9iqb6V4S3ShLZZHBtNtKwE=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 86F4D3858C83
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1759908692; x=1760513492;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=g+flzbUeg0DM4D0VlvUOb8/nKCXo0vuSSqjEfh+vRVI=;
b=py3zXgmDL6WZUOSXj86fpqdAUrLgwnR6ZCG4jf9Pr5wTMc0KEtG6UFbs2bbFhPHZXd
AUTq/ybq9Dk3kKSl2SyKdCxl7pLaA2E4zmp/ig96947E2rXCqmk6CozGsMriKFhF3dQM
iPb+COHveZl4J+dMRFDvNAnTJ/SufuEvqxlVAV7xFegX0o9KieHpuOoTaxsyHwfcvnSz
eV6h3lQ4HFuJR9efPa3ABAceD0oKnLnoe8TMjIVEoKCdoKuATwDvP8EnihNQVXWOhpmZ
NiFPTrbBSIA5XlfdwoGnS2zjE1+SK6zb3JrRuDOdJ2CGOq2pU2sppt8lObCg7F+C3ZF6
pr3A==
X-Gm-Message-State: AOJu0YzvOum7Uo1pVbgZV8kBUa4OK3PiCB3zaprbD/FlL4JD8sHpeyr9
3Awb8pDOm+EIxSOQ/6kxSfvfY6Yx+vmiWMd4QLgud6sa0lLCiA6RNGGhmlOE5q1GQ/DD4AaRwnB
T9De7TJX2uXiC8+AUbVbsh6yMcOLAcnUbo3iHq95KMg==
X-Gm-Gg: ASbGncsw+lM0VY0zxPGMuQ/5ydleF0RGeXQk5y+IOmVPTYAyAIAwjo9hRrHCOhU4bAI
VUvYcEgca5P0JGAYinvF5ScAaOOIXRTP9A6djSgVAaDl+OgMSBK3tTeaTLtaJ2AwlowmskPeHpb
wjIU3tZh7llqjTXnjYxRcYiR1fOvp0ubj5myJ7E3eHPwTDYD1ufrJ7mZRi8IZe2WX/OQgZ+d/9Q
0tzrucoOg/jOgxUzFsxJ1If+bJ7dRxFz2/HVOttCA==
X-Google-Smtp-Source: AGHT+IGkgCSnhKlHCi0kOadqBSrjICcZ5TDjgWZv8Yf9ajeEuGCiQgSOt7vtueKafW4aJGpUSon3L+FCnlqYOlaC2gg=
X-Received: by 2002:a05:651c:35c5:b0:36a:58e0:7ea with SMTP id
38308e7fff4ca-37609eecf64mr6443321fa.44.1759908691324; Wed, 08 Oct 2025
00:31:31 -0700 (PDT)
MIME-Version: 1.0
References: <CANgSWMMdLZa=aN79XgJwYSHyX87bDzcmjEjWTeQL54aybS934A AT mail DOT gmail DOT com>
<76ed6af0-34f2-43e3-893f-f33bc36d7876 AT maxrnd DOT com>
In-Reply-To: <76ed6af0-34f2-43e3-893f-f33bc36d7876@maxrnd.com>
Date: Wed, 8 Oct 2025 08:31:19 +0100
X-Gm-Features: AS18NWCUanlBKdVeiv-tWmexRDOaa8fZSXxpYq6OpyEihmzGDULjJudqtIj1UeE
Message-ID: <CANgSWMNaHh9km3HB4Ng=XG1u1jJ=a_Py=LwzKFLm=75+oUJWXA@mail.gmail.com>
Subject: Re: job control in cygwin bash
To: cygwin AT cygwin DOT com
X-BeenThere: cygwin AT cygwin DOT 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 AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Vadym Krevs via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Vadym Krevs <vkrevs AT gmail DOT com>
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

Hi Mark,

Aha, that explains the results.  That c program and the cl compiler
were only used as a way of showing the difference in process ids. The
script I am trying to port to run on Windows under cygwin does not
really compile C and really needs to run native Windows programs.

Anyhow, thank you very much for a quick reply.

Vadym

On Wed, 8 Oct 2025 at 06:54, Mark Geisert via Cygwin <cygwin AT cygwin DOT com> wrote:
>
> 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 <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 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 "<process.h>" to
> "<unistd.h" and "_getpid" to "getpid" in your source file first.
> HTH,
>
> ..mark
>
> --
> 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

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019