When connecting to a Linux device using a serial port there may be times where that connection becomes stuck open and thus will not provide sane output to the TTY port. This issue can be resolved by killing the PID (Process ID) and letting the serial port process restart.
The serial port connection should be configured in inittab which will allow you to specify various configuration options as well as respawning the process. So when you specify respawn the process will automatically restart if it is no longer running as will be the case if you kill the process off. The inittab entry will look similar to one of the two below examples.
Example One:inittab ttyAM0 configuration
S:2345:respawn:/sbin/getty 57600 ttyAM0
Example Two:inittab ttyS0 configuration
s0:2345:respawn:/sbin/agetty -L -f /etc/issueserial 9600 ttyS0 vt100
So once you verify how the serial connection is configured you will know if you are connecting the proper way and also how you might begin looking into a stuck serial port connection. If a Linux device is waiting for a serial port connection it would look similar to the below.
Linux Waiting on Serial Port Connection:Result of listing processes and grep’ing for tty
root@gesbc-9302:~$ ps -ef | grep tty root 2895 1 1 02:54 ttyAM0 00:00:00 /sbin/getty 57600 ttyAM0
As you can see this Linux device is waiting for a serial connection on ttyAM0 at a speed of 57600. Now once a connection is made to this serial port the output of the exact same command above will look like the below.
Linux With Active Serial Port Connection:
root@gesbc-9302:~$ ps -ef | grep tty root 3037 1 1 02:56 ttyAM0 00:00:00 -sh
You can see the difference between the output of the same command in the different scenarios. Now if you are unable to make a serial connection to the device or if when you make a serial connection (and you are sure you have the correct connection speed) and nothing but gibberish is output to the screen then you can be pretty sure that the serial port connection is stuck in an open mode. To resolve this issue you can simply kill of the serial connection PID (Process ID) and let inittab respawn the process so you can make a new connection. In the last example above called “Linux With Active Serial Port Connection” you would issue the below command to kill off the ttyAM0 serial port connection.
Kill Stuck Serial Port Connection on Linux Server:
root@gesbc-9302:~$ kill -9 3037
To recap we are stopping process ID 3037 which we first verified was the connection attached to ttyAM0 by using the “ps” command.