pgrep.test 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
  3. # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
  4. #cleaning 'yes' processes
  5. killall yes >/dev/null 2>&1
  6. [ -f testing.sh ] && . testing.sh
  7. #testing "name" "command" "result" "infile" "stdin"
  8. # Starting processes to test pgrep command
  9. yes >/dev/null &
  10. proc=$!
  11. #echo "# Process created with id: $proc"
  12. sleep .1
  13. session_id=0
  14. proc_parent=`cat /proc/${proc}/stat | cut -d' ' -f4`
  15. #echo "# Parent Process id of $proc is $proc_parent"
  16. # Testcases for pgrep command
  17. testing "pattern" "pgrep yes" "$proc\n" "" ""
  18. testing "wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" ""
  19. testing "-l pattern" "pgrep -l yes" "$proc yes\n" "" ""
  20. testing "-f pattern" "pgrep -f yes" "$proc\n" "" ""
  21. testing "-n pattern" "pgrep -n yes" "$proc\n" "" ""
  22. testing "-o pattern" "pgrep -o yes" "$proc\n" "" ""
  23. testing "-s" "pgrep -s $session_id yes" "$proc\n" "" ""
  24. testing "-P" "pgrep -P $proc_parent yes" "$proc\n" "" ""
  25. testing "return success" "pgrep yes && echo success" "$proc\nsuccess\n" "" ""
  26. testing "return failure" "pgrep almost-certainly-not || echo failure" \
  27. "failure\n" "" ""
  28. #Clean-up
  29. kill -9 $proc