From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5818 invoked by alias); 31 Oct 2012 14:25:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17365 Received: (qmail 16749 invoked from network); 31 Oct 2012 14:25:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) Date: Wed, 31 Oct 2012 14:25:46 +0000 From: Peter Stephenson To: zsh-user Subject: Re: question about zargs Message-id: <20121031142546.529e1709@pwslap01u.europe.root.pri> In-reply-to: <20121031134007.GA9731@localhost.localdomain> References: <20121031134007.GA9731@localhost.localdomain> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-TM-AS-MML: No On Wed, 31 Oct 2012 21:40:07 +0800 Han Pingtian wrote: > I just learnt that there is a function 'zargs' which just like > 'xargs'. So why we need the 'zargs' as we have 'xargs' already? > > As a example, this works just fine with 'xargs': > > % print -N **/* | xargs -n1 -0 ls It works, but with more processes. zargs allows you to have things (though not ls) running completely in the shell. In that case, you aren't sensitive to the size of the argument list passed to an external process. > But this one will cause "(eval):2: fork failed: cannot allocate > memory" error on my laptop: > > % zargs **/* -- ls ls is run as an external process, so the argument list is limited. zargs doesn't have a builtin system-dependent limit to the number it'll pass in one go, unlike xargs, as far as I can see, so needs to be told how to limit it. Hmm... in principle, you can do: zargs -n2 **/* -- ls so that it executes ls and one additional argument each time. This is equivalent to the -n1 you gave to xargs. However, with a lot of iles this is running incredibly slowly for me and after a few dozen files have been processed I hit: 279: mem.c:1180: MEM: allocation error at sbrk, size 589824. zargs:279: fatal error: out of memory (Luckily this is in a subshell.) It looks like this is hitting some pathology in memory management to do with the argument array (which is being shifted at that line). pws