GithubHelp home page GithubHelp logo

psgrep's Introduction

psgrep

Select processes with the power of Perl expressions!

Basic Usage: grepping

The simple case is simple:

psgrep httpd

That does a regular expression match against the command and arguments shown by ps. On my system, it comes back with:

PID  COMMAND
51   /usr/sbin/httpd -D FOREGROUND -D WEBSHARING_ON
94   /usr/sbin/httpd -D FOREGROUND -D WEBSHARING_ON
2272 /usr/sbin/httpd -D FOREGROUND -D WEBSHARING_ON

Since it's a Perl regex, you can also do stuff like this:

psgrep '^\/System.*\.app\W'  # maybe not so basic

That comes back with results like:

PID   COMMAND
4257  /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
4532  /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock

Other Operations

It's not just grep. You can use most of Perl's comparison operators.

psgrep 'user eq ahall'    # ahall's processes
psgrep 'ppid > 1'         # processes not parented by init (on Unix)
psgrep 'state =~ [Z]'     # zombies

Putting it all together:

psgrep perl 'uid != 0' 'pcpu > 5' # non-root perl scripts using > 5% of cpu

Output

Output looks like ps's. (It essentially is ps's.) Any field you compare against automatically gets printed.

  • -o adds fields to output, just like ps

  • -p prints only matching PIDs, with no header (for script/pipeline use)

Compatibility

It should work with any ps that supports the BSD-style axw options and the POSIX/SUS -o format option. Tested with Perl 5.8.1 and newer, and requires no non-core modules. Just take the script with you wherever you need it.

For More

Run psgrep --man to display the complete manual.

psgrep's People

Contributors

vitahall avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.