mirror of
https://codeberg.org/landley/toybox.git
synced 2026-01-26 14:13:25 +00:00
pgrep currently implements -l and -f, but not -a. It also inadvertently treats -f as a combination of -a and -f, where we both filter via the full command line and display the full command line. This violates --help, where -f says "Check full command line for PATTERN". Implement -a, which takes care of displaying the full command line, and return -f to simply checking (filtering) via command line.
48 lines
1.7 KiB
Bash
48 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
|
|
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
|
|
|
|
#cleaning 'yes' processes
|
|
killall yes >/dev/null 2>&1
|
|
|
|
[ -f testing.sh ] && . testing.sh
|
|
|
|
#testing "name" "command" "result" "infile" "stdin"
|
|
|
|
# Starting processes to test pgrep command
|
|
yes and no >/dev/null &
|
|
proc=$!
|
|
#echo "# Process created with id: $proc"
|
|
sleep .1
|
|
session_id=0
|
|
proc_parent=`cat /proc/${proc}/stat | cut -d' ' -f4`
|
|
#echo "# Parent Process id of $proc is $proc_parent"
|
|
|
|
# Testcases for pgrep command
|
|
testing "pattern" "pgrep yes" "$proc\n" "" ""
|
|
testing "wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" ""
|
|
testing "-l pattern" "pgrep -l yes" "$proc yes\n" "" ""
|
|
testing "-f pattern" "pgrep -f yes" "$proc\n" "" ""
|
|
testing "-a pattern" "pgrep -a yes" "$proc yes and no\n" "" ""
|
|
testing "-la pattern" "pgrep -la yes" "$proc yes and no\n" "" ""
|
|
testing "-fa pattern" "pgrep -fa yes" "$proc yes and no\n" "" ""
|
|
testing "-lf pattern" "pgrep -lf yes" "$proc yes\n" "" ""
|
|
testing "-fa pattern" "pgrep -fa yes" "$proc yes and no\n" "" ""
|
|
testing "-lfa pattern" "pgrep -lfa yes" "$proc yes and no\n" "" ""
|
|
testing "-n pattern" "pgrep -n yes" "$proc\n" "" ""
|
|
testing "-o pattern" "pgrep -o yes" "$proc\n" "" ""
|
|
testing "-s" "pgrep -s $session_id yes" "$proc\n" "" ""
|
|
testing "-P" "pgrep -P $proc_parent yes" "$proc\n" "" ""
|
|
|
|
testing "-f 'full command line'" "pgrep -f 'yes and no'" "$proc\n" "" ""
|
|
testing "-l 'full command line nomatch'" "pgrep -l 'yes and no'" "" "" ""
|
|
testing "-a 'full command line nomatch'" "pgrep -a 'yes and no'" "" "" ""
|
|
|
|
testing "return success" "pgrep yes && echo success" "$proc\nsuccess\n" "" ""
|
|
testing "return failure" "pgrep almost-certainly-not || echo failure" \
|
|
"failure\n" "" ""
|
|
|
|
#Clean-up
|
|
kill -9 $proc
|