While working on a project lately, i needed a script that would allow me to find certain processes with PHP and inspect their running times, etc. After struggling for a little bit, i came up with the following script that can output a plain view, JSON or XML of the running processes whose names match a regular expression passed to the script. The script can also kill all processes that match the search term.

This script is by no means complete, but i thought i’d share it with my readers :)
Save it as process_viewer and run it from the command line.

Please keep in mind that this script is still in a very rough form and should not be used on enterprise products; it’s merely a bit of buggering around for fun :)

Click here to download the script.

Usage:

process_viewer [search_regex] [mode] -o [format]

  • search_regex – search term to find running processes (defaults to .+)
  • mode – script mode (defaults to view)
    • view | kill
  • -o – flag to indicate that the script must output in a specified format
  • format – output format (defaults to plain)
    • plain | json | xml

Sample usage:

./process_viewer bash view -o xml