2 ms·
This is so great! Writing toy kernel modules on your own is a super fun way to get into kernel programming. There's no danger of anything going wrong, especial
by jvns 12y ago
This is so great!
Writing toy kernel modules on your own is a super fun way to get into kernel programming. There's no danger of anything going wrong, especially if you develop inside a VM.
My partner wrote a kernel module for a talk I gave that rickrolls your file system -- it overrides the 'open' system call so that any time you open a '.mp3' file, it plays Rick Astley instead. (this requires you to have Rick Astley already on your computer =))
The source code for that (and a few other toy kernel modules) is at https://github.com/jvns/kernel-module-fun https://github.com/jvns/kernel-module-fun
The rickroll module (by Kamal Marhubi) is the most well commented and fun: https://github.com/jvns/kernel-module-fun/blob/master/rickroll.c https://github.com/jvns/kernel-module-fun/blob/master/rickro...
I wrote a blog post with more about this kernel-programming-for-fun philosophy: http://jvns.ca/blog/2014/01/04/4-paths-to-being-a-kernel-hacker/ http://jvns.ca/blog/2014/01/04/4-paths-to-being-a-kernel-hac...
Of course, writing code for the mainline kernel is a responsible task, but writing kernel code on your own machine that nobody will ever run in production is a great way to learn, and I think it's made me a better programmer.
A few concrete ways I think it's made me a better programmer:
- I now understand the interface between kernel space and userspace much better (I use strace all the time to debug my regular userspace code!)
- realizing that the Linux kernel is just written in C and it's something I can read (and understand! and change!) was a big deal for me
- understanding the basics of the underlying operating system helps me reason about my programs better
- I now feel like if I ran into an actual kernel bug or performance problem, it's something I could conceivably attempt to fix and understand, instead of hiding under the bed and saying OH NO THE KERNEL IT IS TOO HARD