This repository provides a collection of simple Linux kernel modules and user-space programs. Each directory contains a small example that focuses on a particular kernel feature or synchronization primitive.
Detailed README files inside each directory describe the implementation in more depth.
These examples are intentionally small so that beginners can easily read and modify the code. Every kernel module directory includes a Makefile
that builds against the currently running kernel.
- kernel_bit_operation - demonstrates bit operations inside a kernel module.
- kernel_hashtable - shows how to use
linux/hashtable.h
for a hash table. - kernel_list - basic usage of the kernel
list_head
APIs. - kernel_list_clock - measures timing for list operations.
- kernel_rbtree - example of the kernel red–black tree API.
- kernel_rbtree_clock - measures timing for red–black tree operations.
- list_spinlock - uses a spinlock to protect a list.
- lockfree_kernel - simple lock‑free list implementation in kernel space.
- lockfree_user - user-space test program for the lock‑free list.
- mutex_global / mutex_struct - mutex usage with global and struct-scoped locks.
- semaphore - demonstrates kernel semaphore APIs.
- spinlock - basic spinlock usage.
- thread_delay - uses a kernel thread with a delay (
udelay
). - thread_wait_queue - synchronizes threads with a wait queue.
- struct_extern - references a structure declared in another source file.
- persistent - experiments with file I/O and write synchronization.
- makefile - example
Makefile
for building user-space C programs. - user_level - small examples using
fork()
andpthread
.
To build any module, change into its directory and run make
:
cd kernel_list # for example
make # builds hello_module.ko
sudo insmod hello_module.ko
sudo rmmod hello_module
The Makefile
uses the KERNEL_DIR
variable to automatically locate the build directory for your currently running kernel. Run make clean
to remove build artifacts.
Inside the makefile
directory is a simple Makefile
for compiling C programs:
cd makefile
make
./example
.gitignore
ignores build results such asresult
,dump
, and editor backups (*.sw*
).- Some examples (for instance,
persistent
) may require access to a real block device or file system. - Loading kernel modules requires root privileges; ensure your system is configured for module development.
These examples serve as a learning aid for experimenting with kernel data structures, synchronization, and threading. Adjust paths and permissions as necessary for your environment.