#!/bin/sh PROCESSLINE="`ps | grep ./main | grep -v grep`" # Check if the string PROCESSLINE is empty, by using the -n test operator if [ -n "$PROCESSLINE" ]; then echo ==> Process exists, so kill it, dude! PROCESSID="`expr substr \"$PROCESSLINE\" 1 5`" kill -9 $PROCESSID echo Give 1 seconds time to completely stop the running application sleep 1 else echo No such process currently running... fi