title: how to use /dev/ptmx for create a virtual serial port?
body: <p>I have a program, using pyserial, and I want to test it without using a real serial port device.</p>
  
  <p>In windows, I use com0com, and in linux, I know there is a method to create virtual serial port pair without using additional program.</p>
  
  <p>so I look up the manual, and found pts, /dev/ptmx, but I don't know how to create a pair by following the manual, can anyone give me a example?</p>
  
  <p>I tried(in python):</p>
  
  <pre><code>f = open("/dev/ptmx", "r")
  </code></pre>
  
  <p>and it works, /dev/pts/4 is created.</p>
  
  <p>and I tried:</p>
  
  <pre><code>f = open("/dev/4", "w")
  </code></pre>
  
  <p>and the result is:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  IOError: [Errno 5] Input/output error: '/dev/pts/4'
  </code></pre>
  
  <p>edit:
  I found a solution(workround), using socat.</p>
  
  <pre><code>socat PTY,link=COM8 PTY,link=COM9
  </code></pre>
  
  <p>then COM8 COM9 are created as virtual serial port pair.</p>