I have a script that tries to make a DB connection using another program and the timeout(2.5min) of the program is to long. I want to add this functionality to the script.
Do you mean you don't want the error message printed if the process isn't still running? Then you could just redirect stderr: kill $pid 2>/dev/null.
stderr
kill $pid 2>/dev/null
You could also check whether the process is still running:
if ps -p $pid >/dev/null; then kill $pid; fi