title: Screeps Basic OS Functionality
body: <p>So I'm fairly new to Screeps, and I've been iterating over several design decisions for my bot. Some back-story is that I've tried using a decision tree which worked, until it got messy. I then considered a FSM (Finite State Machine), which then led to a HFSM (Hierarchical Finite State Machine), and then someone suggested an OS. I started doing some research on the topic and the only thing that I can truly figure out is the different required items to successfully implement an OS. What is the basic structure of a Screeps OS?</p>
  <h3>Kernel</h3>
  <ul>
  <li>My understanding is that the &quot;Kernel&quot; tracks CPU usage for processes and also tracks how many ticks it might require to run a given process. It provides this data for the task Scheduler, which then places processes into a Queue. How do I track the process from the kernel, is there a callback syntax for a process? I've looked into doing some math such as <code>Game.getCPU - Game.getUsedCpu</code> and mixing it with <code>Game.time</code> to calculate how much effort it takes to actually run the process, but I don't know how to get that data back to the Kernel without just throwing it in memory, which works, but seems like unnecessary overhead.</li>
  </ul>
  <h3>Task Scheduler</h3>
  <ul>
  <li>This one seems the simplest to accomplish, simply build a Stack/Queue for the processes, but what's the syntax here? Do I just create a stack that has a <code>run</code> process in it, then augment with a function that adds new items to the queue? How should I properly decide to add items to the queue? I can arbitrarily add a priority to items, but I feel like there is a better way to handle it.</li>
  </ul>
  <h3>Process</h3>
  <ul>
  <li>This part is hands-down the easiest portion of the OS, just create a Run function for a given process, but somehow I have to make that available to the task scheduler as well as make the kernel aware of it's existence. Furthermore, with this process, should I use a state-machine for each process or should it be abstracted out even further into sub-processes which are also handled by the kernel?</li>
  </ul>
  <p>I've also looked at <code>Public</code> OS's from other players but even the basic ones seem like a different language to me because I don't understand the context fully. Is there any resource you can add, perhaps not even screeps related, that might help?
  This is the only real &quot;Resource&quot; I've been able to locate, and it's sparse at best. <a href="https://wiki.screepspl.us/index.php/Operating_System" rel="nofollow noreferrer">https://wiki.screepspl.us/index.php/Operating_System</a></p>