Sometimes my sshd doesn't restart properly. that's quite bad especially for ssh cause that's the only way of accessing some machines.
I suspect it's because pidof tries to kill not only the main sshd, but also processes from logins that might not even exist any more after killing the main sshd, so pidof gives back bad status.
stop(){
kill $(pidof sshd)
}
restart(){
if pidof sshd >/dev/null; then
stop && start
else
start
fi
}