Pratik Singhal
Pratik Singhal

Reputation: 6492

What is the purpose of ioctl set of functions in linux?

In Linux/freeBSD kernel whenever we have to make a driver module for a device, we make a file in the /dev/ folder and use it to communicate with the other processes.

If that is so, what is the purpose of the ioctl set of functions ? Whatever information, we want to convey with the device driver can be written to/read from this file.

Can anyone please explain it ?

I have tried reading about it on tldp.org but couldn't really understand it.

Upvotes: 3

Views: 1121

Answers (2)

Edward Tomasz Napierala
Edward Tomasz Napierala

Reputation: 1846

It would be possible to just create another device file for "control" tasks and use plain reads/writes on that, instead of ioctl. This way ioctl wouldn't be needed at all. Plan 9 operating system did stuff this way.

Thing is - Unix systems just do it in another way. They always did, and since there isn't anything really wrong with it, and lots of software uses ioctl, why bother changing it?

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409472

ioctl is used for I/O control, and as an example lets take a serial port. You open the serial port device, and can read from the serial port, and write to the serial port, but how do you set e.g. the baud-rate? Or other control options? It's not possible using read or write as those are for reading and writing data from/to the serial port, you need another function for this, which is where the ioctl function comes in.

Upvotes: 2

Related Questions