skip to Main Content

I’m using putty to connect to Centos and sometimes it disconnect, and the open terminals on centos stays open, is there a way by a command line to close/kill all open terminals?

4

Answers


  1. if you are using linux then just find out the process id of the putty

    use ps -a to get PID of process then use kill PID

    on Windows:

    Open the command prompt as the current user or as Administrator.
    Type tasklist to see the list of running processes and their PIDs. ...
    To kill a process by its PID, type the command: taskkill /F /PID pid_number.
    To kill a process by its name, type the command taskkill /IM "process name" /F.
    
    Login or Signup to reply.
    1. Identify processes

      ps -ef | grep -E ‘ssh.*pts’ | grep -v grep |awk -F” ” ‘{print $2}’

    The above script it will give you the PID of those ssh pst connections on your machine; then as Vikas said you can kill those processes, remember be aware by using the kill command.

    NOTE: you can use the last command where you can see a list of the current/olders session on your machine.

    1. Kill processes

      kill -9 PID1 PID2 PID3

    Login or Signup to reply.
  2. Kill old login wit command:

    pkill -o -u $USER sshd
    

    You can use ‘screen’ program for reconnect from where your connection was lost.

    Login or Signup to reply.
  3. If you want to kill all open terminals except for the current one, you can use

    kill $(pgrep bash)
    

    pgrep bash lists the pids of all the active terminals

    if the terminals refuse to die, you can use

    kill -9 $(pgrep bash)
    

    the “-9” is used to send the SIGKILL Signal to the process

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search