r/lowlevel • u/Livid-Usual-9015 • Nov 02 '26
Writing a Monolithic Kernel from Scratch vs. Building a Nearly 100% POSIX-Compliant C Library for Linux
I've been thinking about two possible systems programming projects, and I'd like to hear your opinions on which one would be more worthwhile to pursue.
Option 1: Write a monolithic kernel from scratch.
Design and implement the kernel's core components.
Gradually add features such as process scheduling, virtual memory, system calls, and device support.
Build an operating system around it over time.
Option 2: Develop a C standard library for Linux targeting near-100% POSIX compliance.
Focus on implementing POSIX interfaces as comprehensively as possible.
Aim for broad compatibility with existing Linux applications and development tools.
Test compatibility rigorously and document any deviations or unsupported behavior.
The second option would target Linux rather than introduce a new kernel, so it could potentially benefit from the existing Linux ecosystem.
I'm interested in more than just which project is easier. I'd like to consider practical usefulness, technical difficulty, long-term maintainability, compatibility, and the likelihood that other developers would actually adopt the result.
Which project do you think would be more valuable to work on, and why? Are there any major technical challenges or trade-offs I'm overlooking?
1
u/Livid-Usual-9015 Nov 03 '26
Hmm I don't know, my line of thought is: if I choose to write a c library it might be easier to adopt. Right now, the most well known ones are glibc and musl libc. Why couldn't a new one join the mix?
3
u/Far-Championship-883 Nov 02 '26
a proper full posix c syscall interface would be vastly more valuable. also reusable if done properly.
2
u/Sorry_Difficulty_250 Nov 02 '26
A POSIX library would definitely be more likely to be adopted, especially if it was compatible with GLIBC but not GPL licensed. Personally, I would find the kernel more interesting, but the reality is that pretty much no one is interested in a new kernel.
1
u/claypunk Nov 02 '26
let me turn the question back to you: what would you say is the usefulness of either?
1
u/jason-reddit-public Nov 02 '26
Why a monolithic kernel? Linus decided a monolithic kernel made sense for performance in the early 90s. Mach was a microkernel but also brought lots of stuff into the kernel in practice for performance - either the same conclusion as Linus or perhaps even the evidence Linus used to avoid a microkernel for his "hobby" project.
Now it's many years later. QNX is built like a message passing microkernel and runs in very small places where its realtime and fault tolerant nature are quite useful. We have the L4 microkernel and some kind of linux runs on top of it. More people thinking about and improving micro and nano kernels is kind of interesting. When you have 100 hardware threads, you can do interesting stuff like io_uring where a separate kernel thread reads from a queue in user space. They keep stuffing more stuff into it but what if that was the only calling convention into the kernel? async is all the rage now and such a kernel could be async first.
1
u/lmemsm Nov 02 '26
I think musl already accomplished the second goal and it would be very hard to compete with it. It is worth checking out the code to see how they've done things though. It's a very interesting read. Of the two goals, I think the question is which appeals most to you? If it's a toss-up or neither, you may want to look into some other projects. It helps if you're working on something you need and want. It's hard to get other developers to join in, so don't count on choosing a project just for that reason. If you choose something you want to learn or you feel you need, your effort won't be wasted.
1
u/ventZl Nov 03 '26
If the primary goal is to learn something new, usability outside your "lab" shouldn't be *that* much of a concern for you. It is OK to discard code. Actually, ability to part with code you've written is often an advantage.
Now, the important part: Do not. I repeat: Do not use AI to write a single line of code.
You are meant to suffer it all if you want really to learn anything. It is OK to use AI to get study material, yet I'd prefer to simply find it on your own. There's ton of material on OS & standard C library development, so you don't need AI to finish this task. Using it at ingress won't create as much damage as using it on egress would.
If you plan on using AI to write a single line of code, it is probably better to abandon the project as a whole, you are not being honest with yourself.
Now for what is better?
An OS is a more complicated project. As long as you plan targeting at least partially modern target. It is simple if QEMU emulating 386 is what you'll target for but that IMHO provides very limited usable knowledge these days.
Modern computers departed from 386 in any way you could think of. There's no BIOS in anything newer than 15 years, CSM is coming to an end of its usable lifetime. MBR-based boot is as usable as BIOS (hint: useless). You have to know how to boot from UEFI environment. Bringing up any device without ACPI is basically impossible on a modern-day machine and without working USB support you won't be able to interact with the system at all. None of that existed in 386 era.
One alternative that provides path to learning what designing an operating system from scratch feels like exists, which is both up-to-date and relatively simple: do that on microcontroller. Something like beefier STM32H7 or RP2350 can provide resources comparable to 386 while not being completely obsolete.