Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16503

Re: ‘command … &’ creates subshell

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Eli Schwartz <eschwartz@archlinux.org>
Newsgroups gnu.bash.bug
Subject Re: ‘command … &’ creates subshell
Date Tue, 30 Jun 2020 17:29:04 -0400
Lines 116
Approved bug-bash@gnu.org
Message-ID <mailman.728.1593552564.2574.bug-bash@gnu.org> (permalink)
References <pn9hipci.dag@gnui.org> <ac4a98bd-32f4-5c55-3b8f-1306e9758f54@case.edu> <7dvoi92p.dag@gnui.org> <09ea84b2-4fb1-6b05-7c0b-fe6b2ab00c6f@archlinux.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="23p2O7VoEnMBKOEvvC1FHeiN5RHRmId8O"
X-Trace usenet.stanford.edu 1593552564 29043 209.51.188.17 (30 Jun 2020 21:29:24 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Spam-BL-Results
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1593552549; bh=OVf75lgtq1rCwYQ+SjOItksw3ah9xhX6fXC9rxH6HJQ=; h=Subject:To:References:From:Date:In-Reply-To; b=odi2BWW+wuk6NxqhdFqTkmksvaI62cVtmE2+nK2jPnWomKHy+TBpVjb+RU/mw8sv5 OmVNBeiHG+UQpeqVRmWSwfXNMztVSBKGDiDn/QK7aLm3X7mGbc4NWKjCXxGVuKw4fX B9YqQBJmVThiuTOHzg0TlT11ReyD0zVgSFBSt6PnayQErmj4R68z7AO3+IDhV3n3LK iHmON2LvcHwpvAQkW2A6b2+g9WyKOK9IffJXk7RgQz+PrakNkGASESJ80ojxBl1enQ PpUqWTGCAbEmvtJd0DngvRFTIo5HEqcQO4uh4lslCrMF/hB8Tv3LRTF19JDxQ8OoBD 8dFge33d1RgPXO9We8au1oUWhN7gsKIGgaQgnoJglNNmE1IN38TQ8fC6y0b+rJOwqs OUyP+Y53PhCrdOROBVThjNuTHC5UzlS5Kx8Q8XDXzWJC5/BZPBL9gAHBhN8P/NwEA1 5/Z6U7xjoGxNkHodTo3LHxvG/JMFHMFAq7Z0dT7ADpEbIBC5WjXKqBPzNJAe8Cnhes VLqWcp2u5Kv0oHZfASD4Gii3JLAZ8nYnG806StcA068DETvx7QU47KqOBOqb6HUwAO RQVWwDiqXn6XzshCy5FN0UVimFFnUFX8Csk7yCxtdslFXX++nImeJENlrnyK+qbyLV 8wqGOhkGU/bCBtV+hwYvk6D4=
X-Clacks-Overhead GNU Terry Pratchett
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0
In-Reply-To <7dvoi92p.dag@gnui.org>
Received-SPF pass client-ip=88.198.91.70; envelope-from=eschwartz@archlinux.org; helo=orion.archlinux.org
X-detected-operating-system by eggs.gnu.org: First seen = 2020/06/30 17:29:15
X-ACL-Warn Detected OS = Linux 2.2.x-3.x [generic] [fuzzy]
X-Spam_score_int -53
X-Spam_score -5.4
X-Spam_bar -----
X-Spam_report (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <09ea84b2-4fb1-6b05-7c0b-fe6b2ab00c6f@archlinux.org>
X-Mailman-Original-References <pn9hipci.dag@gnui.org> <ac4a98bd-32f4-5c55-3b8f-1306e9758f54@case.edu> <7dvoi92p.dag@gnui.org>
Xref csiph.com gnu.bash.bug:16503

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 6/30/20 4:37 PM, Dmitry Alexandrov wrote:
> Chet Ramey <chet.ramey@case.edu> wrote:
>> On 6/29/20 4:33 PM, Dmitry Alexandrov wrote:
>>> 1) unexpected, as (a) it does not seem to be documented, (b) itʼs counter-intuitive and (c) other bourne-like shells (busybox ash, dash, ksh93, mksh, zsh) does not do that;
>>
>> It's an opportunity for optimization, not a bug
> 
> I am not saying that this is a bug, only that it is inconsistent with almost any other bourne-like shell.

And I understood Chet's point to be that you shouldn't have "expected"
something which isn't guaranteed. Just because it works out that way,
doesn't mean it has to; it's not like other shells document this behavior.

Relying on undocumented behavior isn't the greatest. :p

>>> 2) inconvenient, as in some cases PID of the parent shell is not an appropriate substitute for the PID of the real process.
> 
>> since the results are correct.
> 
> The results are _different_ across shell and, unfortunately, results provided by Bash are the least useful.  Consider:
> 
> 	$ command … &
> 	[1] 30737
> 	$ strace -p $!
> 	strace: Process 30737 attached
>         wait4(-1,
> 
> :-/

Useful replacements:

You could decline to use "command", and it doesn't involve a shell process.

$ cat &
[1] 2092238
$ ps --pid $! --ppid $!
    PID TTY          TIME CMD
2092238 pts/42   00:00:00 cat

[1]+  Stopped                 cat


If you need to ensure a disk executable is used,

$ "$(type -P cat)" &
[1] 2092352
$ ps --pid $! --ppid $!
    PID TTY          TIME CMD
2092352 pts/42   00:00:00 cat

[1]+  Stopped                 "$(type -P cat)"


Anyway, Chet didn't say it won't be changed to do what you expected;
after all, it's acknowledged as an opportunity for optimization, and
optimization is good..

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: ‘command … &’ creates subshell Eli Schwartz <eschwartz@archlinux.org> - 2020-06-30 17:29 -0400

csiph-web