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

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 to poisonbit Cancel reply