i know that driver is a software that can communicate with the hardware in order to control the device that attached to the computer.whereas kernel module is a small piece of code that can inserted into the kernel to improve the performance of the kernel. I want to ask how do the driver work together with the kernel and what is the main difference between device driver and kernel module,also how do they work?



A kernel module is something very specific: A part of the kernel that's being loaded as a module (i.e. dynamically), after the core kernel starts. That can be anything.

In order to use the hardware you need some parts that reside in the mostly kernel for two reasons:

  1. In order to be able to perform hardware operations that cannot be done or are impractical in userspace, or to be able to keep state outside of a process scope.
  2. Because it would be really really inefficient to do in userspace

In order to manage most hardware you need a kernel-space counterpart. This can be compiled as part of the kernel or as a module that gets loaded later on-demand. With modules one is able not to load all of them.

But modules don't have to be related to hardware only. There are modules that just add functionality like (e.g.) ipv6, firewalling options, etc.

A Driver on the other hand is something that provides easy access to the hardware in general. It usually incorporates all hardware-specific things and exposes a generic API. And by generic I mean something that's generic-enough but not necessarily global or standard. E.g. a driver for ATI graphics cards will expose a common API for all ATI cards, but it may not be the same as other cards.

Drivers can be made in userspace, in kernel (built-in or module) or can have legs at both ends. For example, nowdays' graphics card drivers have a part in the kernel and a part in userspace (e.g. the X server, DRI, etc)

| improve this answer | |

A module is just a bunch of code that can be loaded into Linux.
In Linux:- Frequently, modules will be device drivers (i.e.) the software that drives some specific piece of hardware (device). However there are drivers and modules that don't drive hardware. for example, some Linux systems may have IPv6 support as a loadable module. Or file systems such as ISO-9660 may be drivers or modules.
For more details:-

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.