# Killing a terminal session



## balanga (Aug 8, 2018)

How do you kill a terminal session and get it to return to the login prompt?

I was using `ssh` and managed to hang a program I couldn't get out of so tried to kill the session from another session `ps -aux` and then `kill xxx`.  The hung terminal displays 'Killed by signal 15.' Running `ps -aux` again show another process id attatched to that terminal, but even though I kill it, the login prompt does not return.
What to do?


----------



## Bobi B. (Aug 8, 2018)

Run `ps dax` to see the process tree. Here is how it looks like on my end:


```
PID TT  STAT        TIME COMMAND
...
  572  -  Ss       0:00.02 |-- /usr/sbin/sshd
37332  -  Ss       0:00.02 | `-- sshd: root@pts/0 (sshd)
37334  0  Ss       0:00.04 |   `-- -csh (csh)
37337  0  R+       0:00.00 |     `-- ps dax
```

Kill `sshd` and shell processes for your TTY.

However, AFAIK, authentication is made by the ssh(1); there is no concept of a login prompt (this is not telnet(1)). I don't believe you can "return" to the login prompt. Just kill your session and open a new one.


----------



## balanga (Aug 8, 2018)

Bobi B. said:


> Run `ps dax` to see the process tree. Here is how it looks like on my end:
> 
> 
> ```
> ...



Whenever you exit from a virtual terminal a login prompt appears. This has nothing to do with telnet. I was in an `ssh` when the program I was running hung. I tried to break out of it hoping it would terminate the `ssh` session and bring me back to my terminal session. That is the one which has stopped. 
`ps dax`  shows:-



> 1988    v1   Is+   0:00:00   |-- /usr/libexec/getty Pc ttyv1



If I `kill -9 1988` it simply starts another process with the same details but ttyv1 remains dead.


----------



## Bobi B. (Aug 9, 2018)

I see; you're asking about virtual terminals. Can't help you to recover a virtual console gone in a bad state, but here is how to disconnect from a frozen ssh(1) client session: while in console, where `ssh` is running, press `Enter`, `~` (tilde), `.` (dot).

Imagine this working same as `Ctrl+C` for `ssh`, except ssh normally transmits `Ctrl+C` to the remote host; this sequence will stop it.


----------



## Bobi B. (Aug 9, 2018)

Speaking of which, perhaps `ssh` left your terminal in "cooked" mode and you'll have to reset(1) it. Try to do it blindly, i.e. change to given virtual terminal, `Enter`, `root`, `Enter`, password, `Enter`, `reset`, `Enter` or use `Ctrl-J`, instead of `Enter`.

Or you might try `watch -iW ttyv0` from another terminal (change `ttyv0` with respective TTY), and try to login and reset from there.


----------

