}
proc make_testproc { } {
- global testproc_path testproc_comm testproc1_pid testproc2_pid topdir
+ global testproc_path testproc_comm testproc_arg_str testproc1_pid testproc2_pid topdir
set testproc_realpath "${topdir}/lib/test_process"
set testproc_comm "spcorp"
eof { perror "test proc does not link to test process" }
}
-
- set testproc1_pid [ exec $testproc_path & ]
+ # make a process with the argument set to a fraction of ARG_MAX length
+ # but small enough we do not run TCL out of memory for regular expressions
+ # nor do we get argument list too long (104857 was found to work on Ubuntu 18.04)
+ set max_arg_len [ expr min([ exec /usr/bin/getconf ARG_MAX ], 104857) ]
+ # ensure we have enough slack to launch the test prog and pgrep
+ set reserved_space [expr max([ string length $testproc_path ], [ string length $topdir ] + 10)]
+ set testproc_arg_str "a"
+ set i $reserved_space
+ while {$i<$max_arg_len} {
+ incr i
+ append testproc_arg_str "a"
+ }
+ set testproc1_pid [ exec $testproc_path $testproc_arg_str & ]
set testproc2_pid [ exec $testproc_path & ]
}
spawn $pgrep -d : $testproc_comm
expect_pass "$test" "^${testproc1_pid}:${testproc2_pid}\\s*$"
-# FIXME - Need to test against -f flag
set test "pgrep match against full process name"
-untested $test
+spawn $pgrep -f "$testproc_path\\s+$testproc_arg_str"
+expect_pass "$test" "^$testproc1_pid\\s*$"
set test "pgrep with matching gid"
spawn $pgrep -G $gid $testproc_comm
expect_pass "$test" "^$testproc1_pid\\s+$testproc_comm\\s+$testproc2_pid\\s+$testproc_comm\\s*$"
set test "pgrep with full command line"
-spawn $pgrep -a $testproc_comm
-expect_pass "$test" "^$testproc1_pid\\s+$testproc_path\\s+$testproc2_pid\\s+$testproc_path\\s*$"
+spawn $pgrep -af "$testproc_path$"
+expect_pass "$test" "^$testproc2_pid\\s+$testproc_path\\s*$"
set test "pgrep find newest test pid"
spawn $pgrep -n $testproc_comm