Method of using the Fuser command to kill a terminal (special file)

Source: Internet
Author: User

/*********************************************************************
* Author:samson
* date:11/04/2014
* Test Platform:
* 3.13.0-24-generic
* GNU bash, 4.3.11 (1)-release 
* *************************************************************/

Fuser: Displays the process number using a special file or file system and optionally whether to kill. Because any file or device in GNU Linux is considered a file, the special files mentioned here include, but are not limited to, a directory, an open terminal, an open file, a shared library, A file that has been nmap, a file that is being read and written.
Here's an example of using Fuser to kill a terminal.
At x-windows level, after the use of CTRL+ALT+F1, entered the command line mode of the terminal, in which Emacs opened after the Ctrl+alt+f8 switch back to x-windows operation, at this time using the W command to view the currently logged in terminal, As follows:
ufo@ufo:~$ W
11:41:53 up, 22:46, 9 users, load average:0.41, 0.40, 0.44
USER TTY from login@ IDLE jcpu pcpu WHAT
UFO tty1 11:35 6:17 1.48s 1.11s Emacs
UFO tty8:0 2410 month 10days 6:42m 1.44s gnome-session--session cinnamon
UFO pts/0:0 415 37:37 0.81s 0.81s Bash
UFO PTS/1:0 416 4days 0.40s 0.40s bash
UFO PTS/5:0 416 18:05m 24.21s 5.43s bash
UFO PTS/6:0 416 4days 1.57s 1.57s bash
UFO PTS/7:0 117 1.00s 1.23s 6:46 gnome-terminal
UFO PTS/8:0 416 4days 1.21s 1.21s bash
UFO PTS/9:0 10:18 1:23m 0.12s 6:46 gnome-terminal

Can see tty1 that is just open emacs that terminal, at this time want to directly to shut it off, so swollen do nan.
This is the time to use the powerful fuser command, which allows you to view the current username and process number of the terminal to be turned off:
Tty1 the corresponding device name is/dev/tty1
ufo@ufo:~$ fuser-u/dev/tty1
/dev/tty1:8137 (UFO) 8252 (UFO)
At this point you can see that the user currently using Tty1 is a UFO.

So how do you end the process?
You can use the following command:
ufo@ufo:~$ fuser-u/dev/tty1-k
/dev/tty1:8137 (UFO) 8252 (UFO)
Use the W command again to view the terminal:
ufo@ufo:~$ W
11:42:30 up, 22:47, 9 users, load average:0.23, 0.36, 0.43
USER TTY from login@ IDLE jcpu pcpu WHAT
UFO tty8:0 2410 month 10days 6:42m 1.44s gnome-session--session cinnamon
UFO pts/0:0 415 38:14 0.81s 0.81s Bash
UFO PTS/1:0 416 4days 0.40s 0.40s bash
UFO PTS/5:0 416 18:05m 24.21s 5.43s bash
UFO PTS/6:0 416 4days 1.57s 1.57s bash
UFO PTS/7:0 117 6.00s 1.33s 6:47 gnome-terminal
UFO PTS/8:0 416 4days 1.21s 1.21s bash
UFO PTS/9:0 10:18 1:23m 0.12s 6:47 gnome-terminal
It can be seen that the tty1 process has been terminated;

As for the rest of the fun is only to go to man himself suddenly;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.