Consider a system with limited memory, like a smallish VPS. Suppose there are a handful of processes that need to stay alive, and one process "P" that would be nice to have around, but is not strictly necessary. What I'd like do is keep P around under times of low activity, but when activity picks up beyond a certain threshold, kill off P until activity lowers again, at which time I want P to come back. I'm not sure yet what I'd like "activity" to mean, but it could be any of: memory usage, swap usage, server load values.
I'm already using Monit, so it would be good if this could be accomplished with Monit. Bear in mind that I don't mean process memory usage, I mean overall system load. I don't have to use Monit for this, though, if something else will do the job.
Like cjc said, the best way around this would be to provide enough swap to keep all processes running.
If you have many services you want to keep available (but not necessarily alive/running) you might think about
inetd
-ing them. Then they will be started only when somebody actually connects to a specific port on server. The downside: not all protocols haveinetd
implementations.Rather an old question but my answer to a similar question covers this.
Short version: you can use the STOP and CONT signals to pause and resume most memory-intensive processes, and there's an automated tool that does this for you when server is thrashing.