Raunaq Kochar Raunaq Kochar - 1 month ago 18
Linux Question

Working of ioctl(2)

Please explain to me the working of the

ioctl(2)
system call.

The manual page and wikipedia are neither very informative nor detailed.

What should the file descriptor that is passed as the first argument of
ioctl(2)
be pointing to?

Answer

You have to open the device you want to manipulate before calling ioctl. Then you pass the file descriptor for the device you want to manipulate as the first parameter. You would only call ioctl when there's some particular device that has some particular manipulation that you want to perform on it.

Comments