4. Tips and Tricks

4.1. Killing processes

Let's face it: the only time we use kill to send a signal is to kill a process. And that's why it's called kill.

I usually have netscape crashes, so I have a small shell script that does:
		#!/bin/sh
		ps xu | grep netscape | grep -v grep | awk '{ print $2 }' | xargs kill -9
		
This is what is does:

  1. prints all my processes

  2. takes only the lines containing 'netscape"

  3. discards the line about 'grep netscape'

  4. selects the second column of ps xu ( the one showing the PID)

  5. xargs builds the command "kill -9 PID" by taking everyword coming from the pipe and launching kill -9 on it. If I had several PIDs coming down the pipe, xargs would launch a kill -9 on each of those PIDs.