Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently learning about device developement for linux, I have glaced at some books such as LLD3, .. but I still can't understand what happen when we plug a device into computer, That's my imagination: When we plugs a device into a port, in a magic way, Linux kernel will know what device type and call to appropriate module's probe function to determine if it is exactly device which module need, and the next is magic .... Can anyone correction this?

share|improve this question
what kind of device connecting to what kind of computer ? usb device to a x86 computer (a.k.a. PC) or some other combination ? – MelBurslan Dec 12 '12 at 17:02
is it different depend on device type (usb flash, keyboard)? so we choose the usb flash for example :D – Bình Nguyên Dec 12 '12 at 17:06
then, when you plug this device in, your PC (assumed here as you didn't specify), your X86 processor gets an interrupt, telling it a new hardware has been connected to a certain USB port. Then it is up to the kernel/device developer to decide how to handle this interrupt. – MelBurslan Dec 12 '12 at 17:14
up vote 0 down vote accepted

It's not really magic, it's hardware. Information about peripheral events comes to the CPU thru the front side bus, which is the gateway to other hardware; programmatically (in kernel code) these are dealt with via the concept of the interrupt request (IRQ).

Have a look at these in order:



Now consider that the kernel is what determines what goes on in the CPU. Next:



To get more specific WRT the linux kernel code, it uses handlers which fire on receipt of an interrupt request. The basic parts of this are done with architecture specific asm code, a lot of which you will find in (eg) src/arch/x86/kernel. I don't code in asm (the .S files), so it's greek to me, unfortunately, but the idea here (should be in that wikipedia stuff) is that on receipt of an IRQ, the kernel pre-empts whatever user space code is running in order to process the IRQ (possibly passing something on to whatever user space process).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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