Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

after the kill statement the script prints "Terminated" and the following lines never get executed:


kill -9 `ps -ef | grep MailSender | grep -v grep | awk '{print $2}'`
echo starting

I have even tried to add set +e at the beginning but it still exits after kill.

share|improve this question
up vote 1 down vote accepted

Does the name of your script include MailSender? Try changing it, if so. Also, use pkill -9, it'll be cleaner:


pkill -9 MailSender
echo starting
share|improve this answer
Why not using pkill directly? :) (And - why -9? 'kill -kill' is so harmful...) – Michuelnik Jun 14 '12 at 16:28
Guess I didn't optimise the code far enough, thanks :-) I'm hoping this is a last-resort script, so I didn't argue with the use of SIGKILL. Admittedly, I have used to kill processes when they would lockup but still absort SIGTERMs so there might still be a genuine use to script it. – Jay Jun 14 '12 at 16:31
pkill doesnt work, I guess its because MailSender is an argument: /opt/mono-2.10/bin/mono /etc/sender/MailSender.exe – SCL Jun 14 '12 at 16:33
And if you are under Solaris, don't use killall, which would work the same as pkill under Linux but literally kill all processes under Solaris. – Sven Jun 14 '12 at 16:34
@Dawkins You should be able to do pkill -f "Mailsender.exe" – cjc Jun 14 '12 at 17:33

pkill will kill anything contained MailSender, maybe your script contain MailSender in its name. Change it.

share|improve this answer
No improvement over accepted answer. – Deer Hunter Jan 15 '15 at 5:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.