bugfindutils - Bugs: bug #65890, xargs keeps child processes in...

 
 

bug #65890: xargs keeps child processes in zombie state before starting a new process

Submitter:  Paulo César Pereira de Andrade <pcpa>
Submitted:  Tue 18 Jun 2024 08:18:32 PM UTC
   
 
Category:  xargs Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  None Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 19 Jun 2024 01:25:12 PM UTC, comment #2: 

I did not add a version as it should happen in all versions. Before leaving the version unset I did test with 4.9.0 and the problem still happens. I assume it happens in 4.10.0.

Checking latest source code in https://git.savannah.gnu.org/cgit/findutils.git/tree/xargs/xargs.c I do not see how it could not also happen in the latest changes as it still has:


  /* Make sure to listen for the kids.  */
  signal (SIGCHLD, SIG_DFL);


The fix probably should be to install a signal handler for SIGCHLD and call waitpid in the signal handler.

Paulo César Pereira de Andrade <pcpa>
Wed 19 Jun 2024 08:28:09 AM UTC, comment #1: 

You didn't state what version of findutils this problem affects.  Is this problem reproducible with findutils version 4.10.0?

James Youngman <jay>
Group administrator
Tue 18 Jun 2024 08:18:32 PM UTC, original submission:  

This is a copy of the report at https://issues.redhat.com/browse/RHEL-27230




User has a shell script in the pattern:


tail -n0 -F /var/log/messages | stdbuf -i0 -o0 grep -o ... | stdbuf -i0 -o0 awk ... | stdbuf -i0 -o0 awk ... | stdbuf -i0 -o0 xargs -n1 /path/to/handler


A sample reproducer is:

term1# xargs -n1 echo
test
test
foo
foo

term2# ps ax | grep Z
PID pts/0 Z+ 0:00 [echo] <defunct>


I understand the root cause is because xargs has the code:


   /* Make sure to listen for the kids.  */
  signal (SIGCHLD, SIG_DFL);


and this means it does not synchronously handle SIGCHLD.

There is also the code:


      /* Before forking, reap any already-exited child. We do this so
         that we don't leave unreaped children around while we build a
         new command line.  For example this command will spend most
         of its time waiting for sufficient arguments to launch
         another command line:

         seq 1 1000 | fmt | while read x ; do echo $x; sleep 1 ; done |
         ./xargs -P 200 -n 20  sh -c 'echo "$@"; sleep $((1 + $RANDOM % 5))' sleeper
      */
      wait_for_proc (false, 0u);


It is understood that changing this might require a significant rework of how xargs work.

The reproducer should be a very uncommon usage, as input usually should be very fast, or xargs not used in the way in the user script, and instead use some shell loop construct.

Still, this might be considered a valid usage of xargs, and the process in zombie state looks as if something wrong is happening.

Paulo César Pereira de Andrade <pcpa>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jay (Posted a comment)
  • -email is unavailable- added by pcpa (Submitted the item)
  •  

    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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-b921.
    Corresponding source code