I don't believe you can prevent a process from being killed because there are many ways to kill a process and sometimes it could just hang. However, you can check that if the process is killed (or doesn't exist) then restart it. You can check by ways of from running a 'ps' output or if the process opens up a port. To kill the process, use the 'kill' command.
If you are asking how to write this, do a google search on "bash scripting" and learn how bash works.