What is the equivalent of clear line con 0 in Cisco IOS?
I'm using serial-getty@ttyS0.
In Cisco IOS, clear line con 0 apparently kills an existing serial console session.
The closest low-level equivalent would be to send a SIGHUP to all processes on a particular TTY device. So:
pkill -HUP -t ttyS0 If there is a process that is designed to evade a SIGHUP, you could escalate by removing the -HUP option to use a regular SIGTERM instead, or even further by using SIGKILL with -KILL.
The above method should work irrespective of init system used.
A SIGHUP essentially tells the system that a TTY connection that used a modem was disconnected. With it, most editors (or any programs designed to save the user's work in case of an accidental disconnection) would likely save a backup copy of any unsaved data to minimize the risk of losing work. With SIGTERM, it is more likely that any unsaved work is simply lost; with SIGKILL, any unsaved work in a session that gets terminated will be lost for sure.
Since you seem to be using systemd, a higher-level way to do it would be to use loginctl list-sessions to find the session ID number of the current session on ttyS0, then loginctl kill-session <session ID> to force that session to end.
loginctl list-sessionscommand. I had not known aboutpkill's--terminaloption. Those solutions allow me to rewire my brain.