#!/bin/sh

# Pass the application full path in parameter

# We try to find if there is only one instance of the application path given and kill it

# First we make a ps, remove the start of the PS and everything after the first space (nobody put spaces in directory names... :) )
/bin/ps x | sed -e 's/^\(.....\)...............\([^ ]*\).*/\1 \2/g' > /tmp/$$.tmp

# We keep the '.app' and the '.debug' from this list
( /usr/bin/grep '\.app/[^/]*$' /tmp/$$.tmp | /usr/bin/sed -e 's/\/[^\/]*$//g' ; /usr/bin/grep '\.debug/[^/]*$' /tmp/$$.tmp | /usr/bin/sed -e 's/\/[^\/]*$//g' ) > /tmp/$$-1.tmp

# We grep for the argument passed, and keep only the PID which we kill -TERM
/bin/cat /tmp/$$-1.tmp | grep " $1"\$ | /usr/bin/sed -e 's/^\(.....\).*/\1/g' | /usr/bin/sed -e 's/^ *//g' | /usr/bin/xargs -n 1 /bin/kill -TERM

/bin/rm /tmp/$$.tmp
/bin/rm /tmp/$$-1.tmp
