X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D71C6385829D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1706565683;
	bh=CsiloWmBTrQiCqR/PdUQsrMmAL30kuwPsFnhYS3KjaQ=;
	h=To:Subject:Date:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=fNIf6vsWX5AAmBDrR73FAMs5njMBm7OdSc5Q5nq1v2yoP9sMtmli9OfVb2LkBBnEV
	 0VJl4PTxyGfOZum1gHAWHblJq+4f+SB0ZXv62ulRbtnwjzhgTcVq7ttNihBZorjG2N
	 BdBt4MW21lwv9lqZjS5FlKJxBTb0QZ9FZ+q94RbU=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 954B63858D32
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 954B63858D32
ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706565628; cv=pass;
 b=Pm4jRAnWX7inU4sTgFGIBLTbhvGxWkv5X88Kou620FffChKD9JabnthKqNCOIgbeY5Av0Fk7EHiPKXJVx9CBBhDLq/vt69thYvh4SYOZO+WMcGTtzCGSlaTFM5s74ZEkxboUjI+Q06QJRZ89DMc//gzfRU47/2kPruEasf9J7ik=
ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key;
 t=1706565628; c=relaxed/simple;
 bh=mVuVSyQuVuZOAOb684/vePiyPw3zkqlFDjcEdvaZXX8=;
 h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;
 b=tp/DJf0+FCpbE6O9uRSsv+z24t/5DXuJFKXXa8Rmh5fLTwt0yKaDe39pjUZx1Wq2aJ0c+NykJlLTfYccgvarmxGeG+gptVMUTqksd1Lu+4URVYd7hI10TsLv4ZbIedyqmb/eO7ihQYAsxknzIFIY8XXg5frqSjHcgEtdVQF852s=
ARC-Authentication-Results: i=2; server2.sourceware.org
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=Jamy6ipIpCioEQLhld+Ei/lscgTe0C0PeQvUUYKqgt7JyMllZkTv449ITbvAAMUD2sLpgZnkZkBirAGn/LabE8EI4IyhSSBPclzB6AjAjF+IkULgu25reXFhyOJZTSLbRgKJAMX8OpKnUH7INepeq/MDlEQWys7QUWyxSkUW+KV0ly0jt6YBXGcwKY6QlvHxsI8Bvl/WMNp5aozvV0h6tnyLYGW0YhA0vsfpl0sNUoVu2g8S+UFg0fUBCg+G4Zkr5v1s8w1DROK0bcoy/NuAf/w3gmfd4+Ayv3zRKVBBcjfyvpJuTuZU8XoLbhFo2L6KVtqqIds/9GnFL/QgtqF63g==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=xotFnN7H2VnE3tYe0iUHMH3+/kOGqjPqRcTEOyC3EeE=;
 b=FU/vO3Lw+Gnvm2j+xco31V7wZrVtt+zo5uT/mQTll8qt0HnfNfgUFJwF+bxBziM+ehG4w89HqbHIky5x+5OtFVN16jJ9A8hwzv2KtTwoiv8uZxRS0IiOuYcok5njSbKu4lMOeNlOpF2HbowTQ/e0pt8aa+n414MASGWk3ygqbhEETnzZY/lRQ96XNTgeHWsn5RMKK9y1ZB8t/BsVnTCjPigd3L19HtsJXSUhzpe4S4nE2fOSavLgy0KWcX/68TYkLZnn1VME+1t1PYL8S5l3ZIX/G+8mT8nQWBTAEjEEf1BqwGLAryYjDYncSGGr0o+WEYloBzDXX6h/OZ/rQSdMLg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
 dkim=none; arc=none
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: Re: Setting process command name in forked process
Thread-Topic: Setting process command name in forked process
Thread-Index: AQHaTjFJbF93zhLsSUS7kXKt2AFVP7DsPw7ggAAu1liABCk7AIAAyKlz
Date: Mon, 29 Jan 2024 22:00:22 +0000
Message-ID: <DM6PR20MB347605AD07FF2C854B9BE5AAB17E2@DM6PR20MB3476.namprd20.prod.outlook.com>
References: <DM6PR20MB34760DA0A9B07EDB6BC5C214B1742@DM6PR20MB3476.namprd20.prod.outlook.com>
 <DM8PR09MB7095E65F7C281621A1A7A63BA5792@DM8PR09MB7095.namprd09.prod.outlook.com>
 <DM6PR20MB347644CA2D99E18B0F468578B1792@DM6PR20MB3476.namprd20.prod.outlook.com>
 <Zbd22JXHwwGFQvLa@calimero.vinschen.de>
In-Reply-To: <Zbd22JXHwwGFQvLa@calimero.vinschen.de>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
msip_labels: 
x-ms-exchange-messagesentrepresentingtype: 1
x-tmn: [vT0dkp1BI1mqLXXOW+8fFbOoy24AOcYK]
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: DM6PR20MB3476:EE_|PH7PR20MB5332:EE_
x-ms-office365-filtering-correlation-id: 58beed37-dc1f-425a-a117-08dc2115b108
x-ms-exchange-slblob-mailprops: KW6s2gPZH1dt7xgJadK2PVeqDM5ImhFLP0SgkX8WL3c6r4PpqvA97QdGZEfpyVyEvAIlIgcXj/rejSDC0Bkmv2H3qc2dC7UtTJLCv4lG3qk1WLj4faWeUEO6qM0d9yIkkQXccR2yLT6iQMG/kA7BTzDKknX9m9qPcY1IZfQUqO6+0j9m4rusaLz5pgAzjbmRP09y5E4GUIRfHQuszgxq6e1jwgDAwZKFyZz5outA71wWt71Ktmt8MD7ppCxaNSjcpirLe15DxdQQGnchPwrAPehqXEQlxZ5cfBNnxzxHpvl1GkR68lHvFoyTLSHmz7p5SHz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?=
 =?iso-8859-1?Q?5TCJqTniJD6HmJ6y9CPur3p+mVKL8KSG80zvobuaWWCMLdd15k4y4dl/nc?=
 =?iso-8859-1?Q?p3awjODtJlP92NwJnfVCXK+w8x72FIovKXvJqa+F4dcf8PZAIcXtpHNvFz?=
 =?iso-8859-1?Q?5jEWGOlYsiWqZ+pIlXFNVlm8Iw3msgNgGt9ct6Ww590QX8ofWmpdmhYFOd?=
 =?iso-8859-1?Q?J1fzo4WprrnzXO+inFwDxlwVhv6OMzxvb3tfc7fLBSeFyvm3LQS+7DqbKs?=
 =?iso-8859-1?Q?Whyv/OgqAKvs0tSvQtN9AobXyFDsQTG6moYD4ovPCgnu99WPPvpjBPtZko?=
 =?iso-8859-1?Q?JwBZ907SAovJzwlh40RJlemqbqeesjjUOQh4gCI97WeOJUWcdUDsmbYY1d?=
 =?iso-8859-1?Q?Vx4Qt2RbTdmLg4Xkx2ECq2BHhDArl9rY30Vtge5tomBFHFcEJAdZrfaFLK?=
 =?iso-8859-1?Q?f8OJmL2WJpT+mrfMJe1Q=3D=3D?=
MIME-Version: 1.0
X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-9803a.templateTenant
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: DM6PR20MB3476.namprd20.prod.outlook.com
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-CrossTenant-Network-Message-Id: 58beed37-dc1f-425a-a117-08dc2115b108
X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jan 2024 22:00:22.7354 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR20MB5332
X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT,
 FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS,
 TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-Content-Filtered-By: Mailman/MimeDel 2.1.30
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: Steve Beck via Cygwin <cygwin@cygwin.com>
Reply-To: Steve Beck <stevebeck99@hotmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

Thank you, Corinna and Anton for your replies.  I downloaded procps, and it worked exactly as you described.  I understand this approach is a non-portable hack and to the extent that it matters at all, I'd like to +1 the suggestion/request of picking up support for setproctitle(3) in the next available release.

Thanks again!

Best,
Steve

________________________________
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
Sent: Monday, January 29, 2024 1:58 AM
To: cygwin@cygwin.com <cygwin@cygwin.com>
Cc: Steve Beck <stevebeck99@hotmail.com>
Subject: Re: Setting process command name in forked process

On Jan 26 18:35, Steve Beck via Cygwin wrote:
> Thanks so much for the reply, Anton!  Really appreciate it.
>
> I tried what you proposed.  Here is the code trying both ways
> (overwriting what is referenced by __argv[0] and then reassigning the
> reference).  I compile this code (foo.c) simply as follows: gcc -o foo
> foo.c (with no errors or warnings):
>
> [...]
>         if (fork() == 0)
>         {
>                 extern  char    **__argv;
>
>                 strcpy(__argv[0], "bar");

Don't do that.  It's much too dangerous.

>                 __argv[0] = "bar";

That's ok, but see below.

>                 printf("Retry in Child '%s' (argv[0]) with pid %d setting __argv[0] = 'bar': ps ...\n", argv[0], getpid());
>                 system("ps");

Make sure to install the procps-ng package, and then call

  system("procps -f");

> Here is the output when running foo.exe:
> [...]
> Retry in Child 'bar' (argv[0]) with pid 498 setting __argv[0] = 'bar': ps ...
>       PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
>       446     445     446     108276  pty0     1207519 10:19:37 /usr/bin/bash
>       445       1     445     126652  ?        1207519 10:19:36 /usr/bin/mintty
>       498     497     497     128424  pty0     1207519 10:26:41 /home/sbeck/foo
>       497     446     497     123772  pty0     1207519 10:26:41 /home/sbeck/foo
>       500     498     497     128948  pty0     1207519 10:26:41 /usr/bin/ps
>
> As you can see, in neither case does the ps command seem to accurately
> reflect the change in __argv[0] (although within the program, the
> change occurs to argv[0]).
>
> Can you see what I'm doing wrong?

Actually, that's not your fault.  ps(1) from the cygwin base package
does not support this kind of faking the process name, because it does
not even get the command line of a process.  The information given to
ps(1) is pretty minimal and doesn't allow for stuff like that.  The
process name is always the real executable path the process has been
started through.

However, there's the ps(1) from the procps-ng package, which is called
procps.exe so as not to collide with the basic Cygwin ps.  This ps
fetches process information from /proc, which *is* updated when you
change __argv[0], because the info is fetched in realtime from the
process itself.

So with `procps -f', the output looks like this:

Retry in Child './foo' (argv[0]) with pid 570 setting __argv[0] = 'bar': ps ...
UID        PID  PPID  C STIME TTY          TIME CMD
corinna    569   496 15 10:49 pty0     00:00:00 ./foo
corinna    570   569 19 10:49 pty0     00:00:00 bar
corinna    571   570 99 10:49 pty0     00:00:00 procps -f
corinna    496   495  0 10:18 pty0     00:00:00 -tcsh

Bottom line:

Cygwin does not support this officially.  Changing the global __argv[0]
is a bad hack.  It works, but is non-portable.  In fact, there is no
portable way to do this.  SOme systems have prctl, some have
setproctitle, and some have nothing like this at all, stock Windows for
example.

It's also too late to add something along these lines to Cygwin 3.5,
which is due this week.

What we can do is to support this in the next major version of Cygwin,
in which case I'd prefer to implement this via setproctitle(3), given
this API exists on BSD and Linux.  Whether that implies changing
Cygwin's very simple ps(1) as well, I can't say yet.


HTH,
Corinna

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