{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreihc3j4zzx75gr3zgwtbthgq6nhk3w2ya7ixt5hfxdb5d36cwmjlz4",
    "uri": "at://did:plc:ndtvnkebzmsduapq2rqlsru4/app.bsky.feed.post/3mb53yrchvyq2"
  },
  "path": "/syndications/kl-os-2025-12-29/",
  "publishedAt": "2025-12-29T00:00:00.000Z",
  "site": "https://scientiac.space",
  "tags": [
    "https://scientiac.space/syndications/kl-os-2025-12-29/POSSE",
    "Day 8"
  ],
  "textContent": "Day 8 was about Process. Though, modern operating systems use the concept of threads to provide execution context. We treat processes like individual threads being run for our implementation.\n\nFirst we define a structure for PCB (Process Control Block). We first define `PROC_UNUSED` and `0` and `PROC_RUNNABLE` as `1`. Then we create a structure for a unit process with the following slots:\n\n  * Process ID as an Integer.\n  * State (_`PROC_UNUSED`or `PROC_RUNNABLE`_) as an Integer as defined before.\n  * Stack Pointer as a `vaddr_t` (Virtual Address Type).\n  * Kernel Stack as a list of unsigned `8bit` Integers.\n\n\n\nThe Kernel Stack is essential for saving the registers while context switching.\n\nThen, we defined the `switch_context` function that does the context switching. It takes the previous and next stack pointer as arguments and then switches them during execution. It saves the callee-saved registers into the stack, switches the stack pointer then restores the callee-saved registers from the stack. _The execution context is saved as a temporary local variable on the stack._\n\nThen, we work on process creation. The process creation function `create_process` takes in the entry point of the process as a parameter and then returns the process struct.\n\nThe `delay` function is also created to act as a sleep style function which just does `nop` (Nothing) for 30000000 clock pulses.\n\nThen a **scheduler** is made to make the context switching more autonomous. A scheduler is basically a Kernel program which decides the next process.\n\nThen, in the exception handler, we make it so that each process has it's own independent kernel stack. While switching, the contents of `sscratch` are switched too to resume the execution of process from where it was interrupted as if nothing had happened.",
  "title": "KL-OS: Process",
  "updatedAt": "2026-04-22T08:40:43.812Z"
}