-
-
Notifications
You must be signed in to change notification settings - Fork 4
Process Management
Preemptive weighted round-robin scheduler. Fixed process table (64 entries).
See also: Architecture, Syscalls, Userspace, SMP, Memory Management, Shell
PROC_RUN → PROC_BLOCKED → PROC_ZOMBIE → PROC_EMPTY
- Each process has
sched_weight(1–64) andsched_quantumcountdown - PIT fires at 1000 Hz; ticks decrement quantum, switch when quantum hits 0
- Compositor gets weight 4 for responsive GUI
-
nice/reniceset job weights from the Shell
Created via create_task(func, stack). Run in ring 0 with kernel PML4.
Ring 3 with own PML4. Lifecycle: spawn/schedule (via spawn_user_path or execve) → run → exit → reap.
-
execve(): replaces the calling process's image in place (same pid, same fds, new address space). ELF is loaded into a fresh page directory viaelf_load_image, then the old one is freed (COW-refcount aware). argv is threaded onto the new stack in SysV format. -
spawn(background):spawn_user_path()loads an ELF as asched_managedring-3 process and returns immediately. The scheduler time-slices it — the shell stays responsive. -
exec(foreground): runs the child preemptively while the desktop recomposites at ~16 fps — TUIs render live in the GUI window.kwait()reaps after the child becomes a zombie.
See Userspace.
SYS_FORK (syscall #10) clones the calling ring-3 process via copy-on-write:
-
Refcounted frames:
page_incref()tracks share count;free_page()only frees at last reference -
COW clone:
clone_page_directory_cow()walks user PML4[0..510]; writable leaves downgraded to read-only + COW in both parent & child (refcount bumped), read-only pages (code) shared as-is -
First writer:
vm_handle_faultdetects COW → allocates private copy, drops shared reference -
Return: child gets
fork()==0, parent gets child's PID — both resume in round-robin
-
kwait(pid): block until child exits -
sleep(ms): block withwake_tick, scheduler wakes on timer tick -
cli;hltyield pattern ensures atomic check-then-sleep
A POSIX-style subset in kernel/signal.c:
-
Posted (bit in
sig_pending) and delivered at return-to-ring-3 bysignal_dispatch(called from the syscall entry stub) -
SIG_DFL: terminates (exit code
128+signo) - SIG_IGN: dropped silently
-
User handler: interrupted context saved, trampoline pushed to user stack, handler entered → returns through
SYS_SIGRETURNto restore context -
Ctrl-C: keyboard IRQ posts SIGINT to the foreground process; blocks in
read()are interrupted with-EINTR
preempt_disable/enable guards kmalloc, kfree, EXT2 ops, VFS node pool.
See SMP for multi-core scheduling. Currently APs park in cli;hlt; per-CPU run queues, reschedule IPIs, and TLB shootdown are future work.
Contact: uselessalter on Discord | nyxos@inbox.lv | GitHub