Process (ps) display shortcuts in bash

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...

Slides from LISA 2019 Linux systems troubleshooting #LISA2019 https://t.co/D4dMKflK6R Tue Oct 29 05:59:30 +0000 2019

https://t.co/AGeihMALAv configuring grub2 with EFI Fri Sep 13 05:20:01 +0000 2019

I published a Thing on @thingiverse! https://t.co/IYpRyEb7Hz #thingalert Tue Jul 23 19:27:57 +0000 2019

Nokogiri install on MacOSX https://t.co/v3An0miW9L Fri Jul 12 15:06:49 +0000 2019

HTML email with plain mailer plugin on Jenkins https://t.co/Z6FSDMDjy8 Thu Jul 11 21:07:25 +0000 2019