Re: forked before bash subshell

2016-10-17 Thread L. A. Walsh
Ya know, if you are looking for optimization opportunities, using a temporary file to communicate between processes rather than using an actual pipe, is definitely a performance hit -- ESPECIALLY on Cygwin, where you can't even do a "stat" call on a file without actually opening the file. I

Re: forked before bash subshell

2016-10-15 Thread Chet Ramey
On 10/11/16 10:14 PM, s7v7nisla...@gmail.com wrote: > 1. the script to reproduce > bash-4.4$ cat t.sh > (cd /tmp && sleep 20) & > > echo "end" > > > 2. run it > bash-4.4$ bash t.sh > end > > 3. script end, but there is a new forked script. > bash-4.4$ ps -ef | grep t.sh > 501 50268 1

Re: forked before bash subshell

2016-10-15 Thread L. A. Walsh
Daniel Colascione wrote: On 10/15/2016 12:23 AM, L. A. Walsh wrote: Daniel Colascione wrote: One such case is Cygwin --- I'm not sure how "contrived" it is. Cygwin has an old-fashioned non-COW fork, and to add insult to injury, process creation generally is very slow (~100ms). It pays to

Re: forked before bash subshell

2016-10-15 Thread L. A. Walsh
XiaoBing Jiang wrote: Thank you for your explain! #!/bin/bash (cd /tmp && exec sleep 20) & echo "end" Then, instead of having: $ ./foo end $ ps f -t pts/5 PID TTY STAT TIME COMMAND 7287 pts/5Ss 0:00 bash 20165 pts/5R+ 0:00

Re: forked before bash subshell

2016-10-15 Thread L. A. Walsh
Daniel Colascione wrote: One such case is Cygwin --- I'm not sure how "contrived" it is. Cygwin has an old-fashioned non-COW fork, and to add insult to injury, process creation generally is very slow (~100ms). It pays to eliminate subshells in that environment. Given what Cygwin has to work

Re: forked before bash subshell

2016-10-13 Thread Daniel Colascione
On 10/13/2016 08:05 PM, Bob Proulx wrote: XiaoBing Jiang wrote: Greg Wooledge wrote: If you want to ENSURE that the child shell process is replaced by the external sleep 20, use an explicit exec. yes, I want to know why bash not optimize this. or any strategy ? Because it wouldn't save

Re: forked before bash subshell

2016-10-13 Thread Bob Proulx
XiaoBing Jiang wrote: > Greg Wooledge wrote: > > If you want to ENSURE that the child shell process is replaced by the > > external sleep 20, use an explicit exec. > > yes, I want to know why bash not optimize this. or any strategy ? Because it wouldn't save anything significant. Since the

Re: forked before bash subshell

2016-10-13 Thread XiaoBing Jiang
On Wed, Oct 12, 2016 at 8:23 PM, Greg Wooledge wrote: > On Tue, Oct 11, 2016 at 07:14:24PM -0700, s7v7nisla...@gmail.com wrote: > > why bash bahavior like this? is that a bug? > > > > if not, why should forked before execute subshell? > > Because that's how subshells work.

Re: forked before bash subshell

2016-10-12 Thread Greg Wooledge
On Tue, Oct 11, 2016 at 07:14:24PM -0700, s7v7nisla...@gmail.com wrote: > why bash bahavior like this? is that a bug? > > if not, why should forked before execute subshell? Because that's how subshells work. A subshell *is* a fork. > 1. the script to reproduce > bash-4.4$ cat t.sh > (cd /tmp

forked before bash subshell

2016-10-11 Thread s7v7nislands
1. the script to reproduce bash-4.4$ cat t.sh (cd /tmp && sleep 20) & echo "end" 2. run it bash-4.4$ bash t.sh end 3. script end, but there is a new forked script. bash-4.4$ ps -ef | grep t.sh 501 50268 1 0 10:09AM ttys0150:00.00 bash t.sh 501 50275 50181 0 10:10AM ttys015