DASH Shell discussions
 help / color / mirror / Atom feed
From: Richard Retanubun <richardretanubun@ruggedcom.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: "dash@vger.kernel.org" <dash@vger.kernel.org>
Subject: Re: /bin/dash -c != /bin/bash -c with pgrep
Date: Tue, 24 Jan 2012 15:53:02 -0500	[thread overview]
Message-ID: <4F1F1A2E.5020103@ruggedcom.com> (raw)
In-Reply-To: <4F1F11C8.9000200@ruggedcom.com>

On 24/01/12 03:17 PM, Richard Retanubun wrote:
> On 24/01/12 02:43 PM, Jonathan Nieder wrote:
>> Hi Richard,
>>
>> Richard Retanubun wrote:
>>
>>> /bin/dash -c "pgrep -f /usr/sbin/atftpd"; echo $?
>>> -vs-
>>> /bin/bash -c "pgrep -f /usr/sbin/atftpd"; echo $?
>>>
>>> The dash version returns the PID of the grep itself and thus always succeeds.
>>> The bash version works as expected.
>>
>> As the pgrep(1) manual explains, the running pgrep or pkill process
>> will never report itself as a match.  However, when running pgrep
>> through dash, it reports the process id of the shell executing pgrep,
>> while the bash version and recent dash versions optimize "sh -c
>> 'single command'" to
>>
>> 	sh -c 'exec pgrep -f /usr/sbin/atftpd'
>>
>> so there is no shell process left to report.
>>
>> If that "exec" is specified explicitly, the result is the same in both
>> shells.
>>
>> Hope that helps,
>> Jonathan
> It sure does, thanks a lot Jonathan.
>
> As an addendum, I find using "pgrep -x atftpd" in this case also yields the
> expected output in both shell.
>
> Thanks for your time.
>
> -- RR --
Sorry, one more question to clarify, which "recent dash versions" have the optimization?

Debian changelog from wheezy (0.5.7-2) says this:

0005-SHELL-Disable-sh-c-...diff: back out the optimization
that makes dash -c "script" avoid a fork().  It caused
several packages to fail to build from source (thx Stéphane Glondu, closes: #642922).

So it used to, but does not currently?

-- Richard

  reply	other threads:[~2012-01-24 20:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-24 15:51 /bin/dash -c != /bin/bash -c with pgrep Richard Retanubun
2012-01-24 19:43 ` Jonathan Nieder
2012-01-24 20:17   ` Richard Retanubun
2012-01-24 20:53     ` Richard Retanubun [this message]
2012-01-24 21:03       ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F1F1A2E.5020103@ruggedcom.com \
    --to=richardretanubun@ruggedcom.com \
    --cc=dash@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox