即使是像Linux(Linux)这样强大的操作系统有时也会遇到导致应用程序或程序冻结的问题。
有几种方法可以杀死或退出Linux上的冻结程序。本文将解释如何。
使用 Kill 命令(Use The Kill Command)
在您可以使用 kill 命令之前,您的系统需要知道无响应程序的进程 ID(Process ID) ( PID )。
PID是在任何(PID)Linux 操作系统(Linux OS)上创建时自动识别每个进程的数字。这种方法的一个优点是它适用于所有Linux系统。
查找进程和 PID(Find The Process & PID)
如果您不知道Linux上哪个进程被冻结,两个工具将帮助您找到该进程:top和ps。
Top是一个基于命令行的系统监视器。在命令行中,键入以下内容:
$ top
上面的屏幕截图显示了很多信息。例如,假设Chrome是您计算机上的冻结程序。
您可以看到有四个使用以下 PID 运行的Chrome实例:(Chrome)
要识别您要杀死的特定Chrome实例,请使用ps命令和grep过滤输出。
下面的命令将显示与Chrome关联的正在运行的进程:
ps aux | grep chrome
杀死进程(Kill The Process)
您现在拥有在Linux(Linux)上终止冻结进程所需的两条信息:它的名称和 ID。使用以下命令:
- kill – 按 ID 杀死进程
- killall - 按名称杀死进程
您可以向这两个命令发送其他信号,具体取决于您想要的结果。
例如,如果您想杀死无响应的进程然后重新启动它,您将使用HUP(挂起)信号。
其他终止信号包括:
- SIGSTOP 停止进程
- SIGNINT 中断键盘
- SIGKILL 杀死信号
我们从上面的ps命令中了解到, Chrome实例的(Chrome)PID(PIDs)为3827、3919、10764 和 11679。
要发送终止(kill)信号,请运行以下命令以成功终止所有四个(kill)Chrome实例:
- 杀死-9 3827
- 杀死-9 3919
- 杀死-9 10764
- 杀死-9 11679
您还可以使用下面的单个命令使用killall发送相同的信号:
killall -9 铬(killall -9 chrome)
点击 X(Click The X)
无响应的程序和应用程序通常具有灰色的按钮或不起作用的选项。有时您甚至无法在屏幕上移动应用程序窗口。
最简单的解决方案是单击右上角的X按钮。根据您的操作系统,该按钮可能位于左侧或右上角。
单击X后,您将看到一个包含两个选项的对话框:等待(Wait )或强制退出(Force Quit)。要结束程序,请单击强制退出(Force Quit)。
使用系统监视器杀死 Linux 上的 Linux 进程(Kill a Linux Process on Linux Using System Monitor)
Ubuntu中的默认系统(System)监视器称为Gnome。它可以深入了解在Ubuntu Linux操作系统上运行的所有进程。
用户可以使用图形用户界面(Graphical User Interface)( GUI )执行各种任务,包括Stop、Continue和Kill。
如果您的系统不包含Gnome系统监视器应用程序,请按照以下步骤安装它。此过程适用于所有活动版本的Ubuntu Linux以及Linux Mint和Debian。
- 使用终端键盘快捷键CTRL+ALT+T。然后使用以下命令下载并安装Gnome 系统(Gnome System)监视器。
sudo apt-get install gnome-system-monitor
- 使用以下命令终端(Command Terminal)打开系统监视器:
gnome 系统监视器(gnome-system-monitor)
- 或者,使用GUI导航到Applications,在搜索框中键入system monitor,然后单击图标将其打开。
- 打开您的系统监视器(System Monitor),浏览进程(Processes)列以找到无响应或冻结的程序,选择并右键单击它。
您将看到几个选项,包括:
- 结束进程(End Process)以在清理临时文件时终止应用程序。
- 停止进程(Stop Process)以暂停进程,使您能够在以后继续使用它。
- Kill Process是最极端的选项,如果尝试结束它不起作用,它将起作用以退出冻结的程序
使用 xkill 命令(Use The xkill Command)
Xkill 是一个预装的Ubuntu终止实用程序,您可以使用它来强制终止无响应的Linux进程。这是一个预装在Ubuntu中的工具。
您还可以使用以下命令通过终端在其他发行版上安装它:(Terminal)
sudo apt install xorg-xkill
然后通过键入xkill运行它。你的鼠标会变成一个头骨或一个x。左键单击冻结的程序以将其关闭。
使用 pgrep 和 pkill(Use pgrep & pkill)
一些Linux系统提供称为(Linux)pkill和pgrep的快捷方式来执行与上面讨论的kill和ps相同的任务。
Pgrep将显示进程名称和 ID。例如,运行pgrep chrome查看正在运行的(pgrep chrome )Chrome进程的进程 ID 。然后,您可以将该 ID 与 kill 命令一起使用。
杀戮7012(pkill 7012)
或者,您可以跳过此步骤并使用以下命令杀死所有Chrome实例:
pkill 铬(pkill chrome)
如果您只有一个应用程序实例正在运行,则此解决方案效果很好。但是,如果您打开了同一个程序的多个窗口并且只想杀死一个,请改用XKill。
当程序挂起时,重新启动系统并不总是最方便的选择。如果您同时处理多个项目并且尚未保存您的工作,则尤其如此。
尝试使用上述选项之一作为替代方案,以轻松快速地安全退出Linux上的冻结或无响应程序。
How To Quit Frozen Programs In Linux
Even a robuѕt operating system like Linux can sometimes encounter problems that cause apps or progrаms to freеze.
There are several ways to kill or quit a frozen program on Linux. This article will explain how.
Use The Kill Command
Before you can use the kill command, your system needs to know the Process ID (PID) of the unresponsive program.
PID is a number that automatically identifies each process when created on any Linux OS. An advantage of this method is that it works on all Linux systems.
Find The Process & PID
If you don’t know which process is frozen on Linux, two tools will help you find the process: top and ps.
Top is a command line-based system monitor. From the command line, type the following:
$ top
The screenshot above shows a lot of information. For example, let’s say Chrome is the frozen program on your computer.
You can see that there are four instances of Chrome that are running with the following PIDs:
To identify the specific instance of Chrome you want to kill, use the ps command and grep to filter the output.
The command below will show you the running processes associated with Chrome:
ps aux | grep chrome
Kill The Process
You now have the two pieces of information needed to kill a frozen process on Linux: its name and ID. Use the commands below:
- kill – Kill a process by ID
- killall – Kill a process by name
There are other signals you can send to both commands, depending upon the results you want.
As an example, if you want to kill the unresponsive process and then restart it, you will use the HUP (hang up) signal.
Other kill signals include:
- SIGSTOP to stop the process
- SIGNINT to interrupt the keyboard
- SIGKILL to kill the signal
We learned from the ps command above that the PIDs for the instances of Chrome are 3827, 3919, 10764, and 11679.
To send the kill signal, run the following commands to kill all four instances of Chrome successfully:
- kill -9 3827
- kill -9 3919
- kill -9 10764
- kill -9 11679
You can also use the single command below using killall to send the same signal:
killall -9 chrome
Click The X
Unresponsive programs and apps typically have grayed-out buttons or options that don’t work. Sometimes you can’t even move the app window around the screen.
The easiest solution is to click the X button in the top corner. Depending upon your OS, the button may be on the left or on the right top corner.
After clicking the X, you will see a dialog box with two options: Wait or Force Quit. To end the program, click Force Quit.
Kill a Linux Process on Linux Using System Monitor
The default System monitor in Ubuntu is called Gnome. It gives insights into all the processes running on Ubuntu Linux operating systems.
Users can perform various tasks using the Graphical User Interface (GUI), including Stop, Continue, and Kill.
If your system doesn’t include the Gnome system monitor app, install it by following the steps below. This process works for all active versions of Ubuntu Linux as well as Linux Mint and Debian.
- Use the Terminal keyboard shortcut CTRL+ALT+T. Then use the command below to download and install the Gnome System monitor.
sudo apt-get install gnome-system-monitor
- Open system monitor using Command Terminal with the following:
gnome-system-monitor
- Or, using the GUI, navigate to Applications, type system monitor in the search box, and click on the icon to open it.
- Open your System Monitor, browse the Processes column to find the unresponsive or frozen program, select and right-click on it.
You will see several options, including:
- End Process to terminate the application while cleaning temporary files.
- Stop Process to pause the process enabling you to continue working with it later.
- Kill Process is the most extreme of the options and will work to quit a frozen program if trying to end it doesn’t work
Use The xkill Command
Xkill is a pre-installed Ubuntu kill utility that you can use to force kill an unresponsive Linux process. It is a tool that comes pre-installed in Ubuntu.
You can also install it via the Terminal on other distributions by using the following command:
sudo apt install xorg-xkill
Then run it by typing xkill. Your mouse will turn into a skull or an x. Left-click on the frozen program to close it.
Use pgrep & pkill
Several Linux systems offer shortcuts called pkill and pgrep for performing the same tasks as kill and ps discussed above.
Pgrep will show the process name and ID. For example, running pgrep chrome to see the process ID of the running Chrome process. You can then use that ID with the kill command.
pkill 7012
Or, you can skip this step and use the command below to kill all instances of Chrome:
pkill chrome
This solution works well if you only have one instance of an application running. However, if you have several windows open of the same program and only want to kill one, use XKill instead.
When a program hangs, restarting your system is not always the most convenient option. This is especially true if you are working on several projects at the same time and have not saved your work.
Try one of the options above as an alternative to easily and quickly exit frozen or non-responsive programs on Linux safely.