Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
If you can't use a symlink, then I think you need to click the flag link and ask a moderator to move this question to Stack Overflow since I believe this will involve writing a program to create such a device. mknod can't do it, as far as I know. –  Dennis Williamson Mar 17 '11 at 15:37

1 Answer 1

mknod will work, with some exceptions. The syntax is:

mknod /path/to/new/dev c major minor

So, for example, you should likely be able to create a new pts type device with

mknod /tmp/mypts c 136 0

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):

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

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.

share|improve this answer
    
Ok - I can create such device, but how do I get "the other end" of that terminal - as in the provider, not the client? ptmx does it by making one master, the other one slave. I can't use /dev/ptmx because I need unique name that will not change when the device is not used anymore. (/dev/pts/... devices can get a "reused" number) –  viraptor Mar 24 '11 at 20:20
1  
Might help if you could describe what you're attempting to do. Drive a co-process? something like the script command? I will edit my response to be accurate (the value from the open() on /dev/ptmx is the master, and then you fork another process, open the slave, and then exec() to use the slave). –  malcolmpdx Mar 24 '11 at 21:17
    
I need to query a couple of hosts for the location of that pts and I need it to be there after I ssh to the host. With ptmx, if something releases /dev/pts/10, another ptmx user can get the same device - race condition with my connection - not good. I need that device to be provided on the host by a device mapped from a KVM VM. –  viraptor Mar 24 '11 at 22:26
    
@viraptor - KVM is beyond my experience, but I'll ask what you're going to do with the device once it's there (maybe I'll learn something about KVM). Do you want your ssh connection to use it? –  malcolmpdx Mar 29 '11 at 4:03
    
Cant you use another well-named IPC mechanism like a unix socket and manage the connection to that to whatever the pty ends up being? –  Matthew Ife Dec 7 '13 at 8:53

Your Answer

 
discard

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.