X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACFCF3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1706294178; bh=In4vPBkWp78wlzcS37E4tR57kjCy58RmAIYFud21Cq0=; 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=QJSUA3jSERH2SXEvhg8UAXNI8hsLfuC4Syq4VCjrl75Az+crn/Q+63tLV/hQ7cw7N L+PGVucFq3MXZIR8YvTZR0Y+9nnXPNj5S+WmNGdU+lSgXIR097xAGNJ5SDdwzI/seZ aXLq8U1loBHt4XU8zPq0iza9QJiREz8sIJ6dVI9g= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 077BF3858D33 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 077BF3858D33 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706294156; cv=pass; b=UC4AIdQLKNLERyM1tkk7vTpnUApA3gyKlumMyJytMHP2oqNZAlo2zt5V7l0XfXVmo6rrgBK8vPbB6Ux6vLhD/P9566VX15ToAdhpu7ZF+7a5i9I9kTArrPSb8ApNQr/q/n3FTscmyPuustU43N9sEJh21/yKOMPW8KBNxQ1B2gI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1706294156; c=relaxed/simple; bh=iy8Bd9njvPgS2CFi1I2TWKc9SQ5bg3m42nzzT9gV3xY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PqYzcIQJ3ivMEVUmrO1oq7tSeXt3EdVMNtBQcdUdY1iZ7kqkjRhHow5ysgUFntCcaOuT1Sy7eawPim78ZhW1isdAr8tGM8uZOdy2KmAFj7ntXWJZEBU1mvNjVBaREGVH20zI5Wwwjw9FFhY7zrLEQ3nxucbyNZcn1te/6D/CjJ4= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ANP1X6B6hlZjlgQjqejXP5zWv0EGhtGkI1b3z9bZnd7uFGR/WpeHjzVro4+xKxXO9V+G9ozHrhEsnp0kG9wqUVo4hPwKU6p8DRm4HH6qRGdh4HRnihBdAdymKzUcDylet3+Y/KDVppRpZsU7keesYcBLyM3TRKfVr1wtl3m2botujDSK9gi65CITtwuUs3zeV1YtEfcpFaAf2huLG0Q+uoNvXtfmjCef1EZ74pPn1XS2b3nxBuzpLOJpMsz/CLggPdhuuDd1+nHtF5HxFmbzttIzQLp3ApmPjcijEC36hbunhxIh7qBpJlEs1oHzGh6mAIrjjcb3p6/PNNdq1oPmeA== 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=7yIH+rrPkZxehZblJ2eAbGEhBP4XheHZDTm0cwiRa3M=; b=IjxwUmIzvQwuK4kO9vogjpf/AADjRPg3oxzioSmQtgt1QEupQV5+c90uC8t50FL6gv8CAHVXU0FnINbHp/Rf0R0+2bNIEvE791eD6ZaotLbeNjmI+2V+tQWLbfMMMelz1tfzMT3HLMmP7M68OegnnMQ4EyTi3sykMetI+xDUIct6/uT9EHDYc1+QUleUBO7+bnWf6VKUDbr3mIWAtehusGNLoGo/g5gAgI7ePX9W8OtCkq3ukADdV1nK4N5yQ3+j8RZwB/5g5J4dwGqAxTjzxSGjPQHSGoc64RNtMRsBGWw2JyCLQVXQ6XSV0xfHYUGtZG/mSM5JS8SlhFWPAwU3GA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none To: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" , "cygwin AT cygwin DOT com" Subject: Re: Setting process command name in forked process Thread-Topic: Setting process command name in forked process Thread-Index: AQHaTjFJbF93zhLsSUS7kXKt2AFVP7DsPw7ggAAu1lg= Date: Fri, 26 Jan 2024 18:35:51 +0000 Message-ID: References: In-Reply-To: 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: [uxLMCG0lV7oO1b9x7vgrwGpoUOc23ALk] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR20MB3476:EE_|MW3PR20MB3340:EE_ x-ms-office365-filtering-correlation-id: 1b47117a-b928-49a5-5e46-08dc1e9d9fd1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Hgk7LFCQFezSWIg6nasVakHhFhLT6aEC9MBYlevzaNKLgShptnMJrXQjZN0NpbOYX+957xEh0Vs9Ma4Z+04gMmm89jY1Vok2lLzkGmHJvZJxVIsJzSdV9FBst+lDCOouqOP5tW9Xa+TNCJEiMRreJWeP8b/t/tLPirfSalGZSI/T91JHQ6tvG5Vd6aFi2a95X20RZq3Drk+x5P9OAodm3VQYcClfbPBjInRVbDeY9/UQUd5Ers8ax7uCBD3+XBHynX48dGmFxgXc5IlbxVRkO8VwbQiJrOxAyC40Y9VxA4Z1SFm+k9LWGUnZ99d56LYLDPSwGGSRbAykGHhNBhKc1gqQj65cqMq+ukfOr8gwj0G39q+AC4TPmxTnQod4feNLx2PBJ7e+QdvB+vMe8UYT0VrM52wn7uZ/SEalYr8Nm6N55k1KC8OcGHdZkukhPGGdLmzpdXI4pyAEiHETPiyXifjlreLn2YfJe6Q5jOsCLYyDh9w7Ic7jG5bw6UZUihVqSsRhV5UYQUOaSP/TbpYjkd8g6MC88Uo7oeUMhObDKbAmNcdqrUrdSELfCYHLa0ON x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?rNESvM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KJ3/eHUBw3itq6?= =?iso-8859-1?Q?aV/zFUwye0FdDC0OXjaksALroxfcchwfGiLrfJSYQUoP62+Trk8+PTR0PW?= =?iso-8859-1?Q?NUMzYLB0psl2p3lJoMA0m+xsaaEEAx5b5VaItAXz2Mz+ifuv2bktm3iCnE?= =?iso-8859-1?Q?fZHPN1WZctjY3tYKSlyE3BgPXByCMlMkzCmAd6tcvLumSrQeBBHUDiBtDQ?= =?iso-8859-1?Q?cNWYwAOikqz4HtK5dDYeYjFqAzSrP3hu+9nQKw/5H2UCYBT5msHf3LgZx1?= =?iso-8859-1?Q?4ELxls1sU4Hh5HizdbOFfIyTc0x/W2f59SohGKqhWRhfTyeiRHGx+VgiUF?= =?iso-8859-1?Q?isjkr/SwNIr4mhGQHKh6WUAySa+2nVoj8lLMcZAe8PJnR4Pc7o+o/xz0KW?= =?iso-8859-1?Q?CY/qRC6UZJX4ndcBhokA=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: 1b47117a-b928-49a5-5e46-08dc1e9d9fd1 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jan 2024 18:35:51.9264 (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: MW3PR20MB3340 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, 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 AT cygwin DOT com X-Mailman-Version: 2.1.30 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Steve Beck via Cygwin Reply-To: Steve Beck Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Cygwin" 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): #include #include #include #include extern pid_t getpid(void), fork(void); extern int sleep(int); int main (int argc, char *argv[]) { printf("%s with pid %d: Entered. About to fork child ...\n", argv[0], getpid()); if (fork() == 0) { extern char **__argv; strcpy(__argv[0], "bar"); printf("Child '%s' (argv[0]) with pid %d: ps ...\n", argv[0], getpid()); system("ps"); __argv[0] = "bar"; printf("Retry in Child '%s' (argv[0]) with pid %d setting __argv[0] = 'bar': ps ...\n", argv[0], getpid()); system("ps"); exit(0); } printf("%s parent with pid %d: sleep(5) ...\n", argv[0], getpid()); sleep(5); exit(0); } Here is the output when running foo.exe: foo with pid 497: Entered. About to fork child ... foo parent with pid 497: sleep(5) ... Child 'bar' (argv[0]) with pid 498: 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 499 498 497 125904 pty0 1207519 10:26:41 /usr/bin/ps 498 497 497 128424 pty0 1207519 10:26:41 /home/sbeck/foo 497 446 497 123772 pty0 1207519 10:26:41 /home/sbeck/foo 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? Many thanks, Steve ________________________________ From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] Sent: Friday, January 26, 2024 7:47 AM To: Steve Beck ; cygwin AT cygwin DOT com Subject: RE: Setting process command name in forked process > (I'm assuming it's too late by the time the /proc entry has been set up). Actually, it's not. But beware, the suggested solution is absolutely NOT portable: These are the externals that /proc is referring to... (Not argc, argv passed to main().) extern char** __argv; extern int __argc; So you can change everything that it shows by reassigning __argv(and/or __argc) with a totally different set of arguments, or just modify __argv[0], provided that it fits into the space occupied by the original argument [0]. HTH, Anton Lavrentiev Contractor NIH/NLM/NCBI -- 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