0

What is the equivalent of clear line con 0 in Cisco IOS?

I'm using serial-getty@ttyS0.

2
  • 2
    Questions like "What is the equivalent of command X on system Y" are always hard to answer because there are usually a lot of very fine details of what, exactly, command X does, that can't be 100% replicated. However, it is also likely that you are not really interested in replicating command X 100%. Rather, you have a problem you want to solve, and you know, on system Y you would solve that problem with command X, so you ask about an equivalent to command X. But maybe, the equivalent to command X isn't even the right command to solve the problem! So, rather ask about the problem instead. Commented May 5, 2024 at 16:31
  • Thank you for your advice. I did choose that question because it conveys better what I was thinking about. I had not known about the loginctl list-sessions command. I had not known about pkill's --terminal option. Those solutions allow me to rewire my brain. Commented May 6, 2024 at 5:31

1 Answer 1

2

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.

1
  • What a great answer! Both solutions work fine, and both resemble that command I'm accustomed to. Commented May 5, 2024 at 20:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.