Monday, July 18, 2016

[Quick info: Kill Sessions]: how do I kill another login session remotely?

How do I kill another login session remotely?

You can kill a Unix login session remotely by sending a hangup signal (SIGHUP) to the process running the login session. To do this, follow the steps below:
  1. Identify the shell you want to kill. To determine your current tty, from your Unix shell prompt, enter:
      tty
  2. To show all of your running processes, enter:
      ps -fu username
    Replace username with your username.
  3. You should see something like this:
      PID    TT  STAT   TIME COMMAND
      13964  v5   I      0:00 elm
      13126  ue   S      0:00 -bash (bash)
      13133  ue   R      0:00 ps x
      13335  v5   S      0:00 -bash (bash)
    In the first column, "PID" stands for "process ID". The second column shows the tty to which your processes are connected. The dash (-) before a process name shows that the process is a login shell.
  4. To remove the remote shell, look for the processes with a dash and choose the process number that is not for your current tty. Then issue the following command:
      kill -HUP processid
    Replace processid with the process ID number you identified.
When you send a SIGHUP (by entering kill -HUP or kill -1) to a login shell, all the processes that were started in the shell will be killed as well (unless they were in the background). SIGHUP is good because it allows applications like Elm and Emacs to exit gracefully, leaving your files intact.
Note: You cannot kill processes that are running on a computer different from the one you are logged into. This rule extends to individual nodes within clusters of Unix systems as well.
++++++++=======================================+++++++++++++++++++

Howto: Linux Kill and Logout Users

There is a package called procps. It includes various useful (nifty) utilities. One of such utility is skill which is responsible to send a signal to users and process such as:
  • Halt user terminal
  • Kill user and logout

The procps package contains utilities to browse the /proc filesystem, which is not a real file system but a way for the kernel to provide information about the status of entries in its process table. Procps includes ps, free, skill, pkill, pgrep, snice, tload, top, uptime, vmstat, w, watch and pdwx commands.

Task: How To Halt/Stop a User Called vivek

Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands. First, switch to the root user by typing su – and entering the root password, when prompted (you can also use sudo if configured). Type the skill command as follows:
# skill -STOP -u vivek
The skill command sends a terminate command (or another specified signal) to a specified set of processes.

Task: Resume Halted User Called vivek

Send CONT single to user vivek, type the following command:
# skill -CONT -u vivek

Task: Kill and Logout a User Called vivek

You can send KILL single, type the following command:
# skill -KILL -u vivek

Task: Kill and Logout All Users

The ultimate command to kill and logout all users is as follows:
# skill -KILL -v /dev/pts/*
WARNING! These tools are obsolete, unportable and it is here due to historical reasons. Consider using the killall, pkill, and pgrep commands instead as follows.

pkill command

To halt or stop a user called vivek, enter:
# pkill -STOP -u vivek
To resume a user called vivek, enter:
# pkill -CONT -u vivek
To kill all php-cgi process owned by vivek user, enter:
# pkill -KILL -u vivek php-cgi

Other useful nifty utilities provided by procps package

  • w command : Show who is logged on and what they are doing.
  • kill command : Send signal to a process (explains how to kill process under Linux)
  • top command : Display Linux tasks and other important stuff
  • vmstat command : Display virtual memory statistics.
  • free command : Display free and used memory (RAM) statistics.
  • slabtop command : Display kernel slab cache information in real time.

No comments: