Re: Sleep code

From: Jeremy Elson (
Date: 06/17/94

> Just read your http page on Circle...and got VERY interested in the feature t
> you've called 'sleep code', putting the mud to sleep when no connections.
> I don't want to waste your time, but if you've got a few mins to put together
> a quick e-mail describing how (no code req'd) you've gone about doing the
> 'sleep code', then I'd be very interested...

It's very simple, just 3 or 4 lines of code.  At the beginning of the
game loop, if it senses that there are no descriptors connected, it
uses a select() call with the last argument of NULL instead of the
last argument of a zero-valued time structure.  As the man page for
select() points out, doing so causes the process to block indefinitely
until one of the descriptors in its descriptor set changes.  In our
case, that means going to sleep until a new connection comes in.

The MUD doesn't kill itself or even reboot.  It just gets put asleep
by the operating system.  In other words, it uses **0** CPU time, plus
the OS can page it _completely_ out of memory, so it uses 0 physical
memory as well.  When a new connection comes in, the OS turns the 
process back on, and it continues executing as if nothing had ever

The only downside if this is that none of the heartbeat functions will
be executed while in sleep mode.  i.e., the mayor won't wander around;
zones won't reset; mob's won't wander.  But, I don't see what the point
is of having those things happen if no one is playing anyway.  Besides,
it's easy to disable. :)


This archive was generated by hypermail 2b30 : 12/07/00 PST