interview question how does application connects to device

Greg Freemyer greg.freemyer at gmail.com
Tue Jul 5 08:56:19 EDT 2011


On Tue, Jul 5, 2011 at 12:15 AM, Bond <jamesbond.2k.g at gmail.com> wrote:
> This is an interview question.
>
> I had written device driver for a char device so I know that code
> structure looks like this
>
> struct file_operations something {
>  .owner=my_device_open;
>  .read=my_device_read;
>  .close=my_device_close;
>  .write=my_device_write;
>
>  }
> When the device driver is active then in
>
> /dev/mydevice
> you can actually read and write into it. But what I was not clear is
> how an application will read or write to this device. I know insmod
> will insert the module to kernel,and register_chrdev(); will register
> the driver in kernel but how will application program communicate with
> this driver.
>
>
> My answer was
> In unix it simply opens the device node as a file and sends/receives
> data and commands from it.
>
> But he was expecting some thing more complex.

And the interviewer was right! You fell short.  And so did everyone
else in this thread.  I'm very surprised at the poor answers this
thread generated.  Maybe everyone should get a 20+ year old UNIX book
an read it so they know the basic and classic mechanisms.

My personal favorite old book was

  "The Magic Garden Explained: The Internals of Unix System V Release 4"

To my surprise Amazon has some copies.  New and used.  It's 20 years
old, but it will give some historical pre-linux context.  Remember
your interviewer is likely to be an old timer, so you need to be
familiar with classical UNIX, not just bleeding edge Linux.   (Not
that the answers showed familiarity with either, but the classic stuff
should pop of people's minds without thought.)

Back to the question

read / write are "data" paths, not control/status/command paths. Yes,
there are drivers that abuse read/write to handle commands, but they
are the exception, not the rule.

In general, read/write are termed in-band communications and using
them to communicate with ta driver is discouraged.  The Linux kernel
encourages out-of-band communications.

Let me simplify the question.

1) What are the FIVE classic system calls for interfacing with a
character device.  (ie. If it did not exist in 1970, don't list it).

2) Which of the 5 is still heavily used in the kernel but is
discouraged for new drivers being accepted into the linux kernel?

3) Name at least 3 alternatives that have been routinely used for
out-of-band communication in the Linux kernel since 2000.

Personally, anyone that can't answer those basic questions has failed
a job interview in my mind.

Greg



More information about the Kernelnewbies mailing list