From nobody Thu Mar 24 17:13:01 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 0A7231A32471 for ; Thu, 24 Mar 2022 17:13:04 +0000 (UTC) (envelope-from ganael.laplanche@martymac.org) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4KPWy64SGnz3Fyn for ; Thu, 24 Mar 2022 17:13:02 +0000 (UTC) (envelope-from ganael.laplanche@martymac.org) Received: (Authenticated sender: ganael.laplanche@martymac.org) by mail.gandi.net (Postfix) with ESMTPSA id 88F7D40009 for ; Thu, 24 Mar 2022 17:13:01 +0000 (UTC) Message-ID: <48e49ad0-a12a-d10b-5867-da9736c6c1fd@martymac.org> Date: Thu, 24 Mar 2022 18:13:01 +0100 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 From: Ganael Laplanche Subject: Our /bin/sh and process group IDs To: freebsd-hackers@freebsd.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4KPWy64SGnz3Fyn X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of ganael.laplanche@martymac.org designates 217.70.183.194 as permitted sender) smtp.mailfrom=ganael.laplanche@martymac.org X-Spamd-Result: default: False [-1.49 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.997]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[217.70.183.194:from]; R_SPF_ALLOW(-0.20)[+ip4:217.70.183.192/28:c]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; DMARC_NA(0.00)[martymac.org]; NEURAL_SPAM_SHORT(0.91)[0.910]; MLMMJ_DEST(0.00)[freebsd-hackers]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:29169, ipnet:217.70.176.0/20, country:FR]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[217.70.183.194:from] X-ThisMailContainsUnwantedMimeParts: N Hello, I am trying to fork a sub-shell with its own process group id through a function that must itself be executed in the background. It should work with the following code: #---- #!/bin/sh # Parent shell IDs ps -o pid,ppid,pgid,comm -p $$ test_func () { set -m { /bin/sh -c 'sleep 1' ; } & # Forked shell IDs (pgid should be different from parent, # but it is not) ps -o pid,ppid,pgid,comm -p $! } # The following does not work: test_func & # ...but it works when function is not executed in the background: #test_func sleep 2 exit 0 #---- Unfortunately, with our /bin/sh, the sleeping process gets the *same* process group ID as its parent. I've tested several shell implementations; it works with : /usr/local/bin/bash --posix 'test.sh' # from bash-5.1.16 /usr/local/bin/zsh --emulate sh 'test.sh' # from zsh-5.8.1 /usr/local/bin/ksh93 'test.sh' # from ksh93-devel-2020.06.30 /usr/local/bin/mksh 'test.sh' # from mksh-59c /usr/local/bin/ksh 'test.sh' # from pdksh-5.2.14p2_6 but not with : /bin/sh 'test.sh' # on 13.0-RELEASE-p8 /usr/local/bin/dash 'test.sh' # from dash-0.5.11.5 am I missing something ? Any help welcome :) Best regards, -- Ganael LAPLANCHE http://www.martymac.org | http://contribs.martymac.org FreeBSD: martymac , http://www.FreeBSD.org