Is a device driver in Linux a program/process or is it just a library?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
20
down vote

favorite
4












Is a device driver a program that runs on its own, or is it just a library (a group of functions) that is loaded in memory and programs can call one of its functions (so it is not running on its own).



And if it is a program, does it have a process ID, so can I for example terminate a device driver the same way I can terminate any other process?







share|improve this question


















  • 1




    You can "unload" a driver with rmmod, but only if it's not being used.
    – pjc50
    Oct 16 '17 at 10:25














up vote
20
down vote

favorite
4












Is a device driver a program that runs on its own, or is it just a library (a group of functions) that is loaded in memory and programs can call one of its functions (so it is not running on its own).



And if it is a program, does it have a process ID, so can I for example terminate a device driver the same way I can terminate any other process?







share|improve this question


















  • 1




    You can "unload" a driver with rmmod, but only if it's not being used.
    – pjc50
    Oct 16 '17 at 10:25












up vote
20
down vote

favorite
4









up vote
20
down vote

favorite
4






4





Is a device driver a program that runs on its own, or is it just a library (a group of functions) that is loaded in memory and programs can call one of its functions (so it is not running on its own).



And if it is a program, does it have a process ID, so can I for example terminate a device driver the same way I can terminate any other process?







share|improve this question














Is a device driver a program that runs on its own, or is it just a library (a group of functions) that is loaded in memory and programs can call one of its functions (so it is not running on its own).



And if it is a program, does it have a process ID, so can I for example terminate a device driver the same way I can terminate any other process?









share|improve this question













share|improve this question




share|improve this question








edited Oct 15 '17 at 19:07









GAD3R

22.7k154895




22.7k154895










asked Oct 15 '17 at 11:02









user255688

1013




1013







  • 1




    You can "unload" a driver with rmmod, but only if it's not being used.
    – pjc50
    Oct 16 '17 at 10:25












  • 1




    You can "unload" a driver with rmmod, but only if it's not being used.
    – pjc50
    Oct 16 '17 at 10:25







1




1




You can "unload" a driver with rmmod, but only if it's not being used.
– pjc50
Oct 16 '17 at 10:25




You can "unload" a driver with rmmod, but only if it's not being used.
– pjc50
Oct 16 '17 at 10:25










2 Answers
2






active

oldest

votes

















up vote
32
down vote













On Linux, many device drivers are part of the kernel, not libraries or processes. Programs interact with these using device files (typically in /dev) and various system calls such as open, read, write, ioctl...



There are exceptions however. Some device drivers use a mixture of kernel driver stubs and user-space libraries (e.g. using UIO). Others are implemented entirely in user-space, usually on top of some bit-banging interface (UART or GPIO). In both cases, they’re generally in-process, so you won’t see a separate process, just the process that’s using the device.



To “terminate” a device driver, you’d have to stop all the processes using it, then remove its kernel modules (assuming it’s built as modules), and optionally any other modules it uses and which are no longer necessary. You can list the modules on your system using lsmod, and unload them using rmmod or modprobe -r, both of which will only work if lsmod indicates they have no users.






share|improve this answer


















  • 2




    If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
    – Ruslan
    Oct 16 '17 at 12:14


















up vote
8
down vote













You first have to define what a driver is. I'll define it as a program or subroutine that controls a device (like your camera) or a subsystem (like a file system). Whether it does it directly via the system program or via kernel servers or user-land processes shouldn't in principal matter to this essentially semantic question.



In some cases Linux only provides a generic protocol written in software where the actual "driver" is a device tree. That is a configuration of hardware parameters and which software to use that make up a driver.



Generally speaking driver interfaces and protocols are implemented using kernel modules which are loaded as needed defined by device trees or udev rules. A kernel module is not in the strictest sense a process or library.



A library is just a static set of code that can be loaded into any given process. Modern operating systems load these libraries into shared memory. A process can itself link to any number of shared libraries.



A process is a running program in which the system program or kernel has allocated resources such as system memory and cpu time. Kernel modules may or may not follow this pattern themselves but regardless are not regarded as a defacto processes under Linux.



So to answer your question a driver need not be process but it can be. While the code can exist in a library the driver is still loaded into memery via a program whether it be the kernel in the form of kernel modules or userland processes.



It becomes more of a semantic argument when considering what the totality of a driver actually is. You could say a driver is always a program but sometimes its not like in the case of device trees also it could actually be a userland process, device tree file, udev rules and kernel module where the process and module both use libraries all to make up the logic of a driver.






share|improve this answer


















  • 2




    Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
    – Stephen Kitt
    Oct 15 '17 at 16:11










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398219%2fis-a-device-driver-in-linux-a-program-process-or-is-it-just-a-library%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
32
down vote













On Linux, many device drivers are part of the kernel, not libraries or processes. Programs interact with these using device files (typically in /dev) and various system calls such as open, read, write, ioctl...



There are exceptions however. Some device drivers use a mixture of kernel driver stubs and user-space libraries (e.g. using UIO). Others are implemented entirely in user-space, usually on top of some bit-banging interface (UART or GPIO). In both cases, they’re generally in-process, so you won’t see a separate process, just the process that’s using the device.



To “terminate” a device driver, you’d have to stop all the processes using it, then remove its kernel modules (assuming it’s built as modules), and optionally any other modules it uses and which are no longer necessary. You can list the modules on your system using lsmod, and unload them using rmmod or modprobe -r, both of which will only work if lsmod indicates they have no users.






share|improve this answer


















  • 2




    If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
    – Ruslan
    Oct 16 '17 at 12:14















up vote
32
down vote













On Linux, many device drivers are part of the kernel, not libraries or processes. Programs interact with these using device files (typically in /dev) and various system calls such as open, read, write, ioctl...



There are exceptions however. Some device drivers use a mixture of kernel driver stubs and user-space libraries (e.g. using UIO). Others are implemented entirely in user-space, usually on top of some bit-banging interface (UART or GPIO). In both cases, they’re generally in-process, so you won’t see a separate process, just the process that’s using the device.



To “terminate” a device driver, you’d have to stop all the processes using it, then remove its kernel modules (assuming it’s built as modules), and optionally any other modules it uses and which are no longer necessary. You can list the modules on your system using lsmod, and unload them using rmmod or modprobe -r, both of which will only work if lsmod indicates they have no users.






share|improve this answer


















  • 2




    If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
    – Ruslan
    Oct 16 '17 at 12:14













up vote
32
down vote










up vote
32
down vote









On Linux, many device drivers are part of the kernel, not libraries or processes. Programs interact with these using device files (typically in /dev) and various system calls such as open, read, write, ioctl...



There are exceptions however. Some device drivers use a mixture of kernel driver stubs and user-space libraries (e.g. using UIO). Others are implemented entirely in user-space, usually on top of some bit-banging interface (UART or GPIO). In both cases, they’re generally in-process, so you won’t see a separate process, just the process that’s using the device.



To “terminate” a device driver, you’d have to stop all the processes using it, then remove its kernel modules (assuming it’s built as modules), and optionally any other modules it uses and which are no longer necessary. You can list the modules on your system using lsmod, and unload them using rmmod or modprobe -r, both of which will only work if lsmod indicates they have no users.






share|improve this answer














On Linux, many device drivers are part of the kernel, not libraries or processes. Programs interact with these using device files (typically in /dev) and various system calls such as open, read, write, ioctl...



There are exceptions however. Some device drivers use a mixture of kernel driver stubs and user-space libraries (e.g. using UIO). Others are implemented entirely in user-space, usually on top of some bit-banging interface (UART or GPIO). In both cases, they’re generally in-process, so you won’t see a separate process, just the process that’s using the device.



To “terminate” a device driver, you’d have to stop all the processes using it, then remove its kernel modules (assuming it’s built as modules), and optionally any other modules it uses and which are no longer necessary. You can list the modules on your system using lsmod, and unload them using rmmod or modprobe -r, both of which will only work if lsmod indicates they have no users.







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 16 '17 at 4:15

























answered Oct 15 '17 at 12:22









Stephen Kitt

144k22315379




144k22315379







  • 2




    If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
    – Ruslan
    Oct 16 '17 at 12:14













  • 2




    If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
    – Ruslan
    Oct 16 '17 at 12:14








2




2




If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
– Ruslan
Oct 16 '17 at 12:14





If you're brave enough, and your kernel was compiled with CONFIG_MODULE_FORCE_UNLOAD, you can try rmmod -f to force unload modules which are in use/not designed to be removed/etc.. This will, apart from simply resulting in a kernel in an unreliable state, also taint the kernel.
– Ruslan
Oct 16 '17 at 12:14













up vote
8
down vote













You first have to define what a driver is. I'll define it as a program or subroutine that controls a device (like your camera) or a subsystem (like a file system). Whether it does it directly via the system program or via kernel servers or user-land processes shouldn't in principal matter to this essentially semantic question.



In some cases Linux only provides a generic protocol written in software where the actual "driver" is a device tree. That is a configuration of hardware parameters and which software to use that make up a driver.



Generally speaking driver interfaces and protocols are implemented using kernel modules which are loaded as needed defined by device trees or udev rules. A kernel module is not in the strictest sense a process or library.



A library is just a static set of code that can be loaded into any given process. Modern operating systems load these libraries into shared memory. A process can itself link to any number of shared libraries.



A process is a running program in which the system program or kernel has allocated resources such as system memory and cpu time. Kernel modules may or may not follow this pattern themselves but regardless are not regarded as a defacto processes under Linux.



So to answer your question a driver need not be process but it can be. While the code can exist in a library the driver is still loaded into memery via a program whether it be the kernel in the form of kernel modules or userland processes.



It becomes more of a semantic argument when considering what the totality of a driver actually is. You could say a driver is always a program but sometimes its not like in the case of device trees also it could actually be a userland process, device tree file, udev rules and kernel module where the process and module both use libraries all to make up the logic of a driver.






share|improve this answer


















  • 2




    Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
    – Stephen Kitt
    Oct 15 '17 at 16:11














up vote
8
down vote













You first have to define what a driver is. I'll define it as a program or subroutine that controls a device (like your camera) or a subsystem (like a file system). Whether it does it directly via the system program or via kernel servers or user-land processes shouldn't in principal matter to this essentially semantic question.



In some cases Linux only provides a generic protocol written in software where the actual "driver" is a device tree. That is a configuration of hardware parameters and which software to use that make up a driver.



Generally speaking driver interfaces and protocols are implemented using kernel modules which are loaded as needed defined by device trees or udev rules. A kernel module is not in the strictest sense a process or library.



A library is just a static set of code that can be loaded into any given process. Modern operating systems load these libraries into shared memory. A process can itself link to any number of shared libraries.



A process is a running program in which the system program or kernel has allocated resources such as system memory and cpu time. Kernel modules may or may not follow this pattern themselves but regardless are not regarded as a defacto processes under Linux.



So to answer your question a driver need not be process but it can be. While the code can exist in a library the driver is still loaded into memery via a program whether it be the kernel in the form of kernel modules or userland processes.



It becomes more of a semantic argument when considering what the totality of a driver actually is. You could say a driver is always a program but sometimes its not like in the case of device trees also it could actually be a userland process, device tree file, udev rules and kernel module where the process and module both use libraries all to make up the logic of a driver.






share|improve this answer


















  • 2




    Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
    – Stephen Kitt
    Oct 15 '17 at 16:11












up vote
8
down vote










up vote
8
down vote









You first have to define what a driver is. I'll define it as a program or subroutine that controls a device (like your camera) or a subsystem (like a file system). Whether it does it directly via the system program or via kernel servers or user-land processes shouldn't in principal matter to this essentially semantic question.



In some cases Linux only provides a generic protocol written in software where the actual "driver" is a device tree. That is a configuration of hardware parameters and which software to use that make up a driver.



Generally speaking driver interfaces and protocols are implemented using kernel modules which are loaded as needed defined by device trees or udev rules. A kernel module is not in the strictest sense a process or library.



A library is just a static set of code that can be loaded into any given process. Modern operating systems load these libraries into shared memory. A process can itself link to any number of shared libraries.



A process is a running program in which the system program or kernel has allocated resources such as system memory and cpu time. Kernel modules may or may not follow this pattern themselves but regardless are not regarded as a defacto processes under Linux.



So to answer your question a driver need not be process but it can be. While the code can exist in a library the driver is still loaded into memery via a program whether it be the kernel in the form of kernel modules or userland processes.



It becomes more of a semantic argument when considering what the totality of a driver actually is. You could say a driver is always a program but sometimes its not like in the case of device trees also it could actually be a userland process, device tree file, udev rules and kernel module where the process and module both use libraries all to make up the logic of a driver.






share|improve this answer














You first have to define what a driver is. I'll define it as a program or subroutine that controls a device (like your camera) or a subsystem (like a file system). Whether it does it directly via the system program or via kernel servers or user-land processes shouldn't in principal matter to this essentially semantic question.



In some cases Linux only provides a generic protocol written in software where the actual "driver" is a device tree. That is a configuration of hardware parameters and which software to use that make up a driver.



Generally speaking driver interfaces and protocols are implemented using kernel modules which are loaded as needed defined by device trees or udev rules. A kernel module is not in the strictest sense a process or library.



A library is just a static set of code that can be loaded into any given process. Modern operating systems load these libraries into shared memory. A process can itself link to any number of shared libraries.



A process is a running program in which the system program or kernel has allocated resources such as system memory and cpu time. Kernel modules may or may not follow this pattern themselves but regardless are not regarded as a defacto processes under Linux.



So to answer your question a driver need not be process but it can be. While the code can exist in a library the driver is still loaded into memery via a program whether it be the kernel in the form of kernel modules or userland processes.



It becomes more of a semantic argument when considering what the totality of a driver actually is. You could say a driver is always a program but sometimes its not like in the case of device trees also it could actually be a userland process, device tree file, udev rules and kernel module where the process and module both use libraries all to make up the logic of a driver.







share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 16 '17 at 0:48

























answered Oct 15 '17 at 13:07









jdwolf

2,392116




2,392116







  • 2




    Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
    – Stephen Kitt
    Oct 15 '17 at 16:11












  • 2




    Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
    – Stephen Kitt
    Oct 15 '17 at 16:11







2




2




Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
– Stephen Kitt
Oct 15 '17 at 16:11




Minor quibble: kernel modules can’t be linked to libraries (that’s one of the advantages of writing drivers in user-space).
– Stephen Kitt
Oct 15 '17 at 16:11

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398219%2fis-a-device-driver-in-linux-a-program-process-or-is-it-just-a-library%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay