Home > Bash, linux, Programming > Useful use of pgrep

Useful use of pgrep

To list the PIDs of all running process_name, instead of

ps ax|grep process_name|grep -v grep|awk '{print $1}'

do

pgrep process_name

To kill all running process_name, instead of

for p in `ps ax|grep process_name|grep -v grep|awk '{print $1}'`; do kill $p; done

do

pkill process_name

Advertisements
Categories: Bash, linux, Programming
  1. poisonbit
    December 31, 2009 at 12:24 pm

    Yes, they are much easier to remember.

    In Debian, pkill and pgrep come with the package psmisc (Priority: Optional, so not installed if you don’t choose any item, in tasksel during the installation, and neither any package).

    I use a lot:

    kill -HUP $(pgrep panel)

    When my gnome panel disappears mysteriously, using nvidia and a 3D desktop.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: