low level programming: How does the OS start a new thread/process? low level programming: How does the OS start a new thread/process? multithreading multithreading

low level programming: How does the OS start a new thread/process?


The OS will boot (after the BIOS and the bootloader are done) in a special role - as the first program to run it will have direct access to all the CPUs commands.

So it will setup various parts of the system - like setting up Interrupt Handlers (or Interrupt Service Routines). Having done this it has the ability to create a "scheduler".

The actual "process/thread" handling will be done by this scheduler. It decides, which threads will be run. Also it manages all the active threads. The CPU is unaware of all these things.

Once the scheduler's main-executive decides to execute Thread (or "Process") A, it copys the processes data into the registers (and stores the registers into the recently running thread's InfoBlock). It will tell the CPU / a timer to cause an interrupt in n microseconds (or other timeunit). Then it will tell the cpu to run the "program" (the only thing the CPU knows about) in the non-OS mode (so that it may not modify critical data or register own Interrupt Handlers without permission).

While Thread A is executing now, the hardware timer will run. Once it hits the desired time-offset, it will cause an Interrupt. The hardware will then stop execution of the current program, and will invoke the registred Interrupt Handler instead which. This handler will be a method of the scheduler (the main-executive again, to be precise).

This method will then again reevaluate which Thread should be scheduled and so the scheduling continues.


Correct, during the boot process there is only one execution thread. Usually this is the case until the OS has initialized to the point where low-level memory management, scheduler etc. are functional.

This is even the case in multi-CPU systems - one core is the "master processor" handling the early startup until the infrastructure is there to kickstart the other cores.

In the end it's highly OS-specific; the Intel Architecture Software Developer's Manuals have the details of the hardware specs. (Assuming you're talking about Intel architecture; other architectures might differ wildly.)


One of the first things a (multithreaded) OS has to start is the scheduler which is responsible for managing multiple processes (and therefore also manages multiple CPU threads eg. on multicore machines).

The first process started by this scheduler is typically some sort of "init" process which in turn is responsible for loading the other programs/processes subsequently.