How can we find out the pseudoterminal master and slave from each other?












0














A pseudoterminal has a pair of master and slave.



How can we find out the master device file from a slave device file (e.g. /etc/pts/3)? I only find /dev/ptmx and /dev/pts/ptmx, but they can't be shared by multiple slaves.



Given one of the processes working on the master and slave, how can we find out the other?
For example, ps provides information about the controlling tty of each process. Can it be helpful?



Thanks.










share|improve this question




















  • 2




    Possible duplicate of Are all the slaves paired with the same master?
    – JdeBP
    8 hours ago
















0














A pseudoterminal has a pair of master and slave.



How can we find out the master device file from a slave device file (e.g. /etc/pts/3)? I only find /dev/ptmx and /dev/pts/ptmx, but they can't be shared by multiple slaves.



Given one of the processes working on the master and slave, how can we find out the other?
For example, ps provides information about the controlling tty of each process. Can it be helpful?



Thanks.










share|improve this question




















  • 2




    Possible duplicate of Are all the slaves paired with the same master?
    – JdeBP
    8 hours ago














0












0








0







A pseudoterminal has a pair of master and slave.



How can we find out the master device file from a slave device file (e.g. /etc/pts/3)? I only find /dev/ptmx and /dev/pts/ptmx, but they can't be shared by multiple slaves.



Given one of the processes working on the master and slave, how can we find out the other?
For example, ps provides information about the controlling tty of each process. Can it be helpful?



Thanks.










share|improve this question















A pseudoterminal has a pair of master and slave.



How can we find out the master device file from a slave device file (e.g. /etc/pts/3)? I only find /dev/ptmx and /dev/pts/ptmx, but they can't be shared by multiple slaves.



Given one of the processes working on the master and slave, how can we find out the other?
For example, ps provides information about the controlling tty of each process. Can it be helpful?



Thanks.







linux pseudoterminal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









Stephen Kitt

164k24366445




164k24366445










asked 9 hours ago









Tim

26.1k74246455




26.1k74246455








  • 2




    Possible duplicate of Are all the slaves paired with the same master?
    – JdeBP
    8 hours ago














  • 2




    Possible duplicate of Are all the slaves paired with the same master?
    – JdeBP
    8 hours ago








2




2




Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago




Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago










2 Answers
2






active

oldest

votes


















4














On Linux, using devpts, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx, but there’s no corresponding device node.



See the ptmx manpage for details.



(With BSD-style ptys on Linux, there are matching device pairs, such as /dev/ptyp1 and /dev/ttyp1, respectively on the master and slave side.)






share|improve this answer































    1














    That is one thing that is harder than it should be.



    With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index entry from /proc/PID/fdinfo/FD. See this commit.



    When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX to find all processes that hold a handle to the slave pty.



    With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3) on the file descriptor.






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492302%2fhow-can-we-find-out-the-pseudoterminal-master-and-slave-from-each-other%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      On Linux, using devpts, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx, but there’s no corresponding device node.



      See the ptmx manpage for details.



      (With BSD-style ptys on Linux, there are matching device pairs, such as /dev/ptyp1 and /dev/ttyp1, respectively on the master and slave side.)






      share|improve this answer




























        4














        On Linux, using devpts, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx, but there’s no corresponding device node.



        See the ptmx manpage for details.



        (With BSD-style ptys on Linux, there are matching device pairs, such as /dev/ptyp1 and /dev/ttyp1, respectively on the master and slave side.)






        share|improve this answer


























          4












          4








          4






          On Linux, using devpts, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx, but there’s no corresponding device node.



          See the ptmx manpage for details.



          (With BSD-style ptys on Linux, there are matching device pairs, such as /dev/ptyp1 and /dev/ttyp1, respectively on the master and slave side.)






          share|improve this answer














          On Linux, using devpts, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx, but there’s no corresponding device node.



          See the ptmx manpage for details.



          (With BSD-style ptys on Linux, there are matching device pairs, such as /dev/ptyp1 and /dev/ttyp1, respectively on the master and slave side.)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago

























          answered 8 hours ago









          Stephen Kitt

          164k24366445




          164k24366445

























              1














              That is one thing that is harder than it should be.



              With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index entry from /proc/PID/fdinfo/FD. See this commit.



              When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX to find all processes that hold a handle to the slave pty.



              With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3) on the file descriptor.






              share|improve this answer


























                1














                That is one thing that is harder than it should be.



                With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index entry from /proc/PID/fdinfo/FD. See this commit.



                When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX to find all processes that hold a handle to the slave pty.



                With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3) on the file descriptor.






                share|improve this answer
























                  1












                  1








                  1






                  That is one thing that is harder than it should be.



                  With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index entry from /proc/PID/fdinfo/FD. See this commit.



                  When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX to find all processes that hold a handle to the slave pty.



                  With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3) on the file descriptor.






                  share|improve this answer












                  That is one thing that is harder than it should be.



                  With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index entry from /proc/PID/fdinfo/FD. See this commit.



                  When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX to find all processes that hold a handle to the slave pty.



                  With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3) on the file descriptor.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 6 hours ago









                  mosvy

                  6,1411425




                  6,1411425






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492302%2fhow-can-we-find-out-the-pseudoterminal-master-and-slave-from-each-other%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      濃尾地震

                      How to rewrite equation of hyperbola in standard form

                      No ethernet ip address in my vocore2