killjobs

[last updated - 29 July 2003]

This utility tells the user what processes they are running and asks them if they want to kill them with the -9 option. The only thing new to you here should be the ps -efl call. I am running Cygwin on my PC so I don't know if the field positions are the same. It is up to you to make corrections to this utility if you need to. The PID (process id) should be offered to the user for killing. You are easily at the stage where you can make amendments to this script yourself, if you have carefully gone through all the preceding Unix tips and done all the exercises.


#!/bin/sh
# Script     : killjobs
# Version    : 1.0
# Author     : Roland Rashleigh-Berry
# Date       : 29 July 2003
# Contact    : roland@rashleigh-berry.fsnet.co.uk
# Purpose    : To selectively kill -9 Unix processes owned by the user
# SubScripts : none
# Notes      : This script issues kill -9 commands. It would be better if you
#              tried kills without the -9 option before resorting to this. You
#              can list your processes by using the command:
#              ps -efl | egrep "$USER|PPID"
#              ...and issue kills without the -9 options as you like.
# Usage      : killjobs
# 
#================================================================================
# PARAMETERS:
#-pos- -------------------------------description--------------------------------
# N/A  (none) 
#================================================================================
# AMENDMENT HISTORY:
# init --date-- mod-id ----------------------description-------------------------
# 
#================================================================================
# This is public domain software. No guarantee as to suitability or accuracy is
# given or implied. User uses this code entirely at their own risk.
#================================================================================

ps -efl | egrep "$USER|PPID" > $HOME/ps.tmp

cat $HOME/ps.tmp

cat $HOME/ps.tmp | awk -F' ' '{if (NR>1) {print $2}}' > $HOME/killjobs.tmp

echo
for pid in `cat $HOME/killjobs.tmp` ; do
  echo -n "Do you want to kill -9 process $pid (y/n)? "
  read resp
  if [ "$resp" = "y" ] ; then
    kill -9 $pid
  fi
done

rm -f $HOME/killjobs.tmp $HOME/ps.tmp

Go back to the home page.

E-mail the macro and web site author.