pkill and pgrep truncates process lists to 2048 bytes (below ARG_MAX in syslimits.h)

Number:rdar://FB8926031 Date Originated:2020-12-03
Status:Open Resolved:
Product:macOS Product Version:10.15.7
Classification: Reproducible:Yes
The `/usr/bin/pkill` and `/usr/bin/pgrep` utilities when used with the `-f` option (match against the full argument list) truncate process lists to 2048 characters, despite `ps` utility on macOS showing command lines longer then 2048 characters and supporting command lines of 256 kB as output from `getconf ARG_MAX` utility, and as specified in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/syslimits.h

Steps to reproduce.

1. Run the following in one terminal 

bash -s %testbug% $(seq -w 1 600)

2. Then run in another terminal (bash or zsh)

for i in $(seq -w 1 600) ; do
  REGEX="bash -s [%]testbug[%].* $i"
  if ! /usr/bin/pgrep -q -a -f "$REGEX"  ; then
    echo "error: pgrep failed for regex '$REGEX'"
    if test -n "$PREV_REGEX"; then
      echo "previously worked for regex '$PREV_REGEX'"

**Expected results**: no output should be written.

**Actual results**: the following is written:

error: pgrep failed for regex 'bash -s [%]testbug[%].* 508'
previously worked for regex 'bash -s [%]testbug[%].* 507'


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!