I gave a talk on processes and made some simple shortcuts to show processes matching patterns.

psg

ps - grep, grep the process listing for something and show the parent pid, sort by pid.

function psg() {
  thing=$1
  sort=$2
  if [ -z $2 ]; then
    sort='pid'
  fi
  ps -eo 'pid ppid stat cmd' --sort $sort| awk 'NR==1 {print}; /$thing/ && !/awk "NR==1/ {print}'
}

psgi

ps - grep case insensitive.

function psgi () 
{ 
    thing=$1;
    sort=$2;
    if [ -z $2 ]; then
        sort='pid';
    fi;
    ps -eo 'pid ppid stat cmd' --sort $sort | awk "BEGIN{IGNORECASE = 1}; NR==1 {print}; /$thing/ && "'!/awk "NR==1/ {print}'
}

psk

ps - kernel, show the kernel processes

function psk() {
  ps -eo 'pid ppid stat cmd' --sort pid |awk 'NR==1 {print}; $2==2 {print}' |less
}

pss

ps - sorted by pid (or any other sort field)

function pss() {
  sort=$1
  if [ -z $1 ]; then
    sort='pid'
  fi
  ps -eo 'pid ppid stat cmd' --sort $sort |less
}

psz

ps - look for Zombie processes

function psz() {
  sort=$1
  if [ -z $1 ]; then
    sort='pid'
  fi
  ps -eo 'pid ppid stat cmd' --sort $sort| awk 'NR==1 {print}; $3=="Z" {print}'
}

Of these, I use psg a lot. I use awk to print the first header line and then any matches.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

About the Author...