Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On a gentoo-Linux a process is communicating with another computer via serial port (/dev/ttyS1). I want to listen to this communication (i.e. what is being sent/received by the process) without further interfering.

How can I achieve to do this with just basic linux tools? I even can change the serial port the process is communicating with, so maybe I can 'shortcut' two devices (/dev/ttyS1 and /dev/xxx) to listen to all communication, when all output to /dev/ttyS1 is forwarded to /dev/xxx and vice versa? But how to do it? Something with socat?

share|improve this question
ethtool ? yes I know it will not work but you never know –  Kiwy Feb 24 '14 at 13:31
I am looking for basic linux tools, nothing exotic. –  Alex Feb 24 '14 at 13:49
Nothing exotic about ethtool. –  terdon Feb 24 '14 at 14:19

2 Answers 2

up vote 3 down vote accepted

One approach (not necessarily the best...) would be to attach strace to the process (or, in order to handle the race condition, to a wrapper script which execs to this process), set strace to maximum string length and then catch all read()s and write()s (or whatever your process uses). After that you grep the lines with the right file descriptor (which should always be the same; if not then you have to catch the open()s, too).

share|improve this answer
Nice idea, but what are the file descriptors for /dev/ttyS1? –  Alex Feb 24 '14 at 13:49
@Alex That depends on what the process is doing. You can see them in /proc/$PID/fd and in strace as the return value of the open() calls. –  Hauke Laging Feb 24 '14 at 13:53
See also the -e read=x -e write=y options to get a hex dump of what is read/written on fd x. –  Stéphane Chazelas Feb 24 '14 at 14:34

interceptty looks like what you want.

I found that from this Ubuntu page

interceptty - Intercept traffic to and from a serial port.


If you want to use interceptty as an external serial monitor [connected to two serial ports on your machine and relaying between them, while recording the output]

you can use one device as the backend, and use the -p option to tell the frontend not to create it's own tty, but just use the one you tell it:

interceptty -s 'ispeed 19200 ospeed 19200' /dev/ttyS0 -p /dev/ttyS1 -


interceptty prints its output in a fairly unattractive, painful to look at format. However, it is very easy for other programs to parse. For an example of how to post-process this output into something appropriate to whatever you are intercepting, see the included Perl script interceptty-nicedump.

Output lines are in this general format:

< 0x54 (T)

  0x4b (K)  ^ Direction    ^^^^ Hex code (to real device)
    ^^^ ASCII character (to real device)
     ^^^^ Hex code (from real device)
          ^^^ ASCII character (from real device) The direction marker is a '<' if this character was sent to the backend device, and

'>' if it was received from the backend device. It is always followed by a single space. If the character was received from the real device, a tab will appear next (this makes the output easier to follow). After that is the hex code for the character, and the ASCII representation of the character if it is an ASCII character.

share|improve this answer
it look nice though if ethtool is exotic I can't even think about a tool nobody ever heard of :D –  Kiwy Feb 24 '14 at 14:09
Could you add an explanation of what this does and the minimum info necessary to make it work? I mean in the actual answer, rather than as links to external sources. –  terdon Feb 24 '14 at 14:16
@terdon Have added appropriate example command line. –  X Tian Feb 24 '14 at 14:29
Thanks, upvoted. –  terdon Feb 24 '14 at 14:36

Your Answer


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.