Why would it be killed off?
Because it's not automatic that something is killed. Once you answer that, and explain why something would be selected for destruction, you might be able to come up with a solution.
Given you're talking about Rails'
rake command, I'm guessing that this is a process running on a server. That you're worried about it being killed suggests it's being killed by the server host for using too many resources. In cases like this, there aren't (nor should there be) ways of stopping your process for being killed.
If you have a resource-expensive task, buy more resources. Use your own server time. Or come to an arrangement with the host that allows you to run it on their dime.