User Abdelhadi Khiati shows us how to create a FreeBSD kernel module. Follow the link below for the full set of instructions.

userconfigFreeBSD is one of the biggest OSs in history. It is Unix flavored and based on the Berkeley Software Distribution. Even though Linux is dominating most of the servers market nowadays, FreeBSD still got its fair share (Netflix).
We won’t dive into the reasons why you would want to use FreeBSD as your OS for production (Not the purpose of this post).
I have been lucky enough to participate in Google Summer of Code with the FreeBSD foundation. I was amazed by the community surrounding it which was noob friendly and very helpful (Thank you FreeBSD <3).
I wanted to make a starting tutorial for people to write a simple module for kernel before diving inside more complicated kernel shizzle.

The kernel module that we will be working on is a simple event handler for the kernel. It will be composed of 2 parts, the event handling function, and the module declaration.

The module event handler is a function that handles different events for the module. Like the module being loaded, unloaded or on system shutdown.

You can find the different kind of events that the module can handle here .

MOD_LOAD is set when the module is being loaded inside the kernel.

MOD_UNLOAD is set when the module is unloaded from the kernel.

MOD_SHUTDOWN is set on system shutdown.

MOD_QUIESCE is set when the module is about to be unloaded.

Full tutorial: http://meltmes.kiloreux.me/create-your-first-freebsd-kernel-module/