bugfindutils - Bugs: bug #7340, xargs -n does not execute commands...

 
 

bug #7340: xargs -n does not execute commands in a timely manner

Submitter:  Stewart Brodie <sbrodie>
Submitted:  Tue 20 Jan 2004 02:15:50 PM UTC
   
 
Category:  xargs Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  jay
Originator Name:  Open/Closed:  Closed
Release:  None Fixed Release:  4.2.9
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 05 Dec 2004 05:18:08 PM UTC, comment #4: 

You can download a release of findutils in which this problem is
fixed from ftp://alpha.gnu.org/gnu/findutils.

The releases on alpha.gnu.org are for testing purposes, so please
take the time to download the release and verify that your
problem has been solved.  Once the release has been sufficiently
tested, it can be uploaded to ftp.gnu.org for everybody to use it.

James Youngman <jay>
Group administrator
Wed 24 Nov 2004 05:01:00 PM UTC, comment #3: 

This problem is fixed in the CVS code for findutils.
To resolve your problem, you could either wait for the
next official release of findutils, or check out a copy
of the code from the CVS repository for findutils.

James Youngman <jay>
Group administrator
Mon 01 Nov 2004 10:47:30 AM UTC, comment #2: 

I disagree.  I have improved testit.sh to more clearly demonstrate the problem.  It now has two echo commands with a sleep between them.  The first echo provides enough parameters for xargs to run immediately before the sleep occurs.  It doesn't actually execute until the echo after the sleep has executed.

I have tested and reproduced this behaviour against both versions 4.1.7 and 4.2.3.

Stewart Brodie <sbrodie>
Sat 16 Oct 2004 08:20:23 PM UTC, comment #1: 

I have just retested this problem in findutils 4.2.0 with the "testit.sh" script (attached).  It looks right to me, could you comment on whether you agree?

James Youngman <jay>
Group administrator
Tue 20 Jan 2004 02:15:50 PM UTC, original submission:  

When the number of parameters to the xargs subcommand is limited by using -n <num>, xargs does not execute the subcommand until it has seen the end of the input stream OR num+1 arguments.  This can result in unnecessary delays in execution where the command to be executed is known (it has seen num args) since it isn't actually executed until more arguments are discovered (or the input stream ends).

A (lame, but the best I could think of right now) example which assumes date outputs 6 words:

$ for i in 1 2 3 4; do date;date;sleep 3; done | xargs -n 6

Example output from this is shown below, with me inserting <delay 3 seconds> where the 3 second delays occur:

Tue Jan 20 14:09:35 GMT 2004
<delay 3 seconds>
Tue Jan 20 14:09:35 GMT 2004
Tue Jan 20 14:09:38 GMT 2004
<delay 3 seconds>
Tue Jan 20 14:09:38 GMT 2004
Tue Jan 20 14:09:41 GMT 2004
<delay 3 seconds>
Tue Jan 20 14:09:41 GMT 2004
Tue Jan 20 14:09:44 GMT 2004
<delay 3 seconds>
Tue Jan 20 14:09:44 GMT 2004

There is no apparent reason why the delays are occurring where they are - the second echo should be being executed as soon as 6 parameters are available, no?  I don't think that the current behaviour is desirable (and it's a nuisance for my use of it).

I've tested this against findutils 4.1.7, but I've examined the latest (revision 1.17 of xargs/xargs.c) in CVS and it hasn't changed in this regard.

I think it would be fairly easy to fix this behaviour by inserting a check for reaching max_args near the end of the push_arg function after the new (non-NULL) argument has been added to the argument array, and calling do_exec immediately if the limit has been reached.

But I'm not certain, hence I'm not supplying a proposed patch at the moment.  Does anybody else agree?


Stewart Brodie <sbrodie>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #1953:  test_sb.sh added by sbrodie (86B - text/x-sh - Simple shell script demonstrating the delay)
file #1874:  testit.sh added by jay (179B - application/x-sh)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follow 7 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2004-12-05 jay Assigned toNone jay
    Open/ClosedOpen Closed
    Fixed ReleaseNone 4.2.9
2004-11-24 jay StatusWorks For Me Fixed
2004-11-01 sbrodie Attached File- Added test_sb.sh, #1825
2004-10-22 jay StatusNone Works For Me
2004-10-16 jay Attached File- Added testit.sh, #1767

Back to the top

Powered by Savane 3.13-758e.
Corresponding source code