I'd like to create a character device which has the same properties as a standard pseudo-terminal, but that can be named in a specific name.
Basically I'd like to have /dev/pts/my-unique-name instead of the numbers which can be reused. Is there a way to do that? Can mknod
for example create arbitrarily connected char-devices?
mknod will work, with some exceptions. The syntax is:
So, for example, you should likely be able to create a new pts type device with
What I've found, however, is that if you try to do this in /dev/pts, you will get an access denied message. I can do it in /dev, just not /dev/pts. I'm on a Centos 5.5 box. YMMV.
This is because /dev/pts is mounted by the kernel (from my /etc/fstab file):
This is a kernel-managed pseudo filesystem, and I wouldn't think that screwing around with it is a good idea. The standard way to get a new file created in there is by open()ing /dev/ptmx; that will get the calling process the fd of the master terminal assigned, and a new device will be created as /dev/pts/X where X is dynamically allocated by ptmx as the slave. This would then be opened itself, usually by a forked process from the original one.
There's likely a good reason why it's done this way. I'm not sure what it is, but I would avoid trying to break it, if system stability is something you value.
That all being said, the first command line with real options I presented would allow you to make your own pts device anywhere but /dev/pts, and depending on what you're intending to do with it, maybe that's enough to get you where you're going.
What you are asking for is essentially a use case for using BSD pseudoterminals. The BSD pseudoterminal device driver had 256 pairs of inode numbers (with each pair consisting of a master and a slave), and the corresponding inodes were created in /dev at install and left that way.
Nothing in the kernel enforced any particular naming, but an application needing to search for an unused pair would usually have some expectations about the naming.
Most people consider BSD pseudoterminals to have become obsolete with the introduction of Unix 98 pseoduterminals. And it appears multiple Linux distributions have dropped support for BSD pseudoterminals. However if you can find a kernel which still has support for BSD pseudoterminals, then you can use that support to create a pair of device inodes exactly like you are asking for.
Notice that those have to remain outside of
/dev/pts
, as/dev/pts
is for Unix 98 pseudoterminals.If you just need to transfer a stream of characters and don't need all the other features a pseudoterminal has to offer, then it may be easier to use a named pipe.