当程序在Windows中停止响应时,大多数用户都知道如何通过按键盘上的Ctrl + Alt + Delete来停止它,按任务管理器(Task Manager)选项并从那里关闭它。这种方法并不能完全转移到像Ubuntu这样的(Ubuntu)Linux发行版上,但这并不意味着当程序崩溃时你没有选择。
相反,有很多方法可以使用CMD在(CMD)Ubuntu上关闭程序。如果您习惯使用终端,您可以使用killall或xkill 之(xkill)类的命令来强制关闭麻烦的程序,或者您可以使用系统监视器(System Monitor)应用程序来代替。
使用系统监视器强制关闭正在运行的 Ubuntu 进程(Using The System Monitor To Force Close a Running Ubuntu Process)
虽然使用终端在Ubuntu(Ubuntu)中关闭一个打开的进程很容易,但初学者可能会觉得这样做不太舒服。但是Ubuntu用户不需要靠近终端来强制关闭崩溃的程序——您可以使用系统监视器(System Monitor)应用程序来代替。
系统监视器(System Monitor)的工作方式与Windows PC的(Windows PCs)任务管理器(Task Manager)非常相似。它列出了您 PC 上所有正在运行的进程,并为您提供有关CPU(CPU)、RAM和磁盘使用情况的实时信息。它还允许您强制关闭任何不会响应或直接关闭的崩溃软件。
- 要使用系统监视器(System Monitor)强制关闭Ubuntu中的程序,请按Ubuntu底座底部的显示应用程序按钮。(Show Applications)在您的应用程序(Applications)列表中,单击系统监视器(System Monitor)图标以启动它。
- 系统监视器(System Monitor)应用程序将启动,默认进程(Processes)选项卡可见 - 如果没有,请单击顶部的进程选项卡。(Processes)在进程列表中,找到并找到崩溃程序的进程(或多个进程),右键单击该条目,然后按Kill选项。或者,选择进程并按“系统监视器(System Monitor)”窗口底部的“结束进程”按钮。(End Process)
- 系统监视器(System Monitor)将要求您确认您确实要结束正在运行的进程。要确认,请按终止进程(Kill Process)按钮。
如果成功,该进程应该从您的系统监视器(System Monitor)进程列表中消失。如果程序有一个打开的窗口,这个窗口也应该在此时关闭。
如果系统监视器(System Monitor)没有成功关闭程序,您需要尝试使用终端。
如何使用 xkill 命令关闭打开的窗口(How To Close An Open Window Using The xkill Command)
在大多数情况下,系统监视器(System Monitor)软件会强制关闭Ubuntu上的程序。如果没有,那么您需要切换到终端以关闭所有无响应的程序。
值得庆幸的是,有一个名为xkill(xkill)的易于使用的命令,可让您强制关闭任何打开窗口的程序。
- 大多数现代版本的Ubuntu都应该安装了xkill包,但是,如果你发现它没有安装,你需要先安装xkill才能使用它。打开终端并输入sudo apt install xorg-xkill来执行此操作。安装后,只需键入xkill或sudo xkill即可开始使用它。
- 终端输出将告诉您选择您希望使用按钮 1 杀死其客户端的窗口(select the window whose client you wish to kill with button 1)。换句话说,用鼠标点击一个打开的窗口——xkill 会为你关闭它。一旦被终止,终端输出将在结束前以终止创建者(killing creator)消息进行响应。
这仅适用于明显没有响应的程序,包括任何带有您可以与之交互的GUI窗口的程序。(GUI)
使用pkill、kill 或 killall 命令强制关闭Ubuntu上的程序(Ubuntu Using)
使用 xkill 要求您使用带有GUI的(GUI)Ubuntu。如果您正在运行没有安装 GUI 的无头版本的Ubuntu ,(GUI)例如(Ubuntu)Ubuntu Server(Ubuntu Server),那么您将需要使用pkill、kill或killall命令。
kill和pkill命令将终止您 PC 上运行的任何单个进程,而killall将(killall)杀死所有相关进程。某些程序(例如Google Chrome)使用多个系统进程,因此如果程序停止响应,使用kill或pkill不一定会结束它们。
- 要使用kill,您需要知道分配给它的进程 ID 号 ( PID ) — 打开终端并键入top以查看当前正在运行的进程的列表。您将在PID列下找到进程 ID 号,在(PID)Command列下找到进程/程序的名称。
- 要使用kill(kill)停止终端,请键入kill pid,将pid替换为您的进程 ID(例如kill 582)。如果它不起作用,请键入sudo kill pid。成功的进程终止不应导致任何额外的终端输出,但您可以再次键入top进行仔细检查。
- pkill命令不需要进程 ID 号,但它确实需要包名称。您可以在Command(Command)列下使用top first 进行检查。准备好后,键入pkill process,将process替换为包名称(如果进程不会终止,则sudo pkill process )。与kill一样,成功的pkill命令将不返回任何消息或输出。
- 如果一个程序有多个进程,您可以使用killall命令一次将它们全部终止。与pkill一样,它使用包名——使用top在(top)Command列下找到它。要使用killall,请键入killall process或sudo killall process,将process替换为包名称。与pkill一样,如果命令成功,终端将不会返回任何消息。
有效的 Ubuntu 维护(Effective Ubuntu Maintenance)
即使运行的软件停止响应,Ubuntu也会为您提供保持控制的工具。现在您知道如何使用终端关闭Ubuntu中的进程,您可以利用其他酷炫的 Linux 终端命令(cool Linux terminal commands)来备份您的 PC、暂停正在运行的命令而不是结束它们等等。
崩溃的程序应该很少发生,但如果它发生的频率比它应该的多,它可能表明您的Ubuntu安装存在问题。您需要研究Ubuntu 崩溃的一些常见原因,(common reasons for Ubuntu crashes)以(希望)解决您的问题。
Forcefully Close a Program in Ubuntu
When a program stops responding in Windows, moѕt υsers know how to stop it by pressing Ctrl + Alt + Delete on their keyboard, pressing the Task Manager option and closing it from there. That aрproach doesn’t quite transfer to Linux diѕtributions likе Ubuntu, but that doesn’t mean that you’re short of options when a program crashes.
On the contrary—there are quite a few ways to close a program on Ubuntu using CMD. If you’re comfortable using the terminal, you can use commands like killall or xkill to force troublesome programs to close, or you can use the System Monitor app instead.
Using The System Monitor To Force Close a Running Ubuntu Process
While it’s easy enough to close an open process in Ubuntu using the terminal, beginners might not feel comfortable doing this. But an Ubuntu user doesn’t need to go near the terminal to force close a crashed program—you can use the System Monitor app instead.
The System Monitor works a lot like the Task Manager does for Windows PCs. It lists all the running processes on your PC, as well as giving you real-time information on your CPU, RAM, and disk usage. It also allows you to force close any crashed software that won’t respond or close directly.
- To force close a program in Ubuntu using the System Monitor, press the Show Applications button at the bottom of the Ubuntu dock. In your Applications list, click on the System Monitor icon to launch it.
- The System Monitor app will launch with the default Processes tab visible—if it doesn’t, click on the Processes tab at the top. In the processes list, find and locate the process (or processes) for your crashed program, right-click the entry, then press the Kill option. Alternatively, select the process and press the End Process button at the bottom of the System Monitor window.
- System Monitor will ask for confirmation that you do want to end the running process. To confirm, press the Kill Process button.
If it was successful, the process should disappear from your System Monitor processes list. If the program had an open window, this window should also close at this point.
If System Monitor didn’t successfully close the program, you’ll need to try using the terminal instead.
How To Close An Open Window Using The xkill Command
In most cases, the System Monitor software will forcefully close a program on Ubuntu. If it doesn’t, then you’ll need to switch to the terminal to close any non-responding programs.
Thankfully, there’s an easy-to-use command called xkill that will allow you to forcefully close any program with an open window.
- Most modern versions of Ubuntu should come with the xkill package installed but, if you find it isn’t installed, you’ll need to install xkill first before you can use it. Open a terminal and type sudo apt install xorg-xkill to do this. Once it’s installed, simply type xkill or sudo xkill to begin using it.
- The terminal output will tell you to select the window whose client you wish to kill with button 1. In other words, use your mouse to click on an open window—xkill will close this for you. Once killed, the terminal output will respond with a killing creator message before ending.
This will only work for programs that are visibly not responding, including any programs with a GUI window that you can interact with.
Forcefully Closing a Program on Ubuntu Using pkill, kill Or killall Commands
Using xkill requires you to be using Ubuntu with a GUI. If you’re running a headless version of Ubuntu without a GUI installed, such as Ubuntu Server, then you’ll need to use the pkill, kill or killall commands instead.
The kill and pkill commands will terminate any single process running on your PC, while killall will kill all related processes. Some programs (such as Google Chrome) use multiple system processes, so using kill or pkill may not necessarily end them if the program stops responding.
- To use kill, you’ll need to know the process id number (PID) assigned to it—open a terminal and type top to view a list of currently running processes. You’ll find the process id number under the PID column and the name of the process/program under the Command column.
- To stop a terminal using kill, type kill pid, replacing pid with your process id (for instance, kill 582). If it doesn’t work, type sudo kill pid instead. A successful process termination shouldn’t result in any extra terminal output, but you can type top again to double-check.
- The pkill command doesn’t require a process id number, but it does require the package name. You can check this using top first under the Command column. Once you’re ready, type pkill process, replacing process with the package name (or sudo pkill process if the process won’t terminate). As with kill, a successful pkill command will return no messages or output.
- If a program has multiple processes, you can use the killall command to terminate them all at once. Like pkill, this uses the package name—use top to find this under the Command column. To use killall, type killall process or sudo killall process, replacing process with the package name. Like pkill, no messages will be returned at the terminal if the command is a success.
Effective Ubuntu Maintenance
Even when running software stops responding, Ubuntu gives you the tools to stay in control. Now you know how to close a process in Ubuntu using the terminal, you can take advantage of other cool Linux terminal commands to backup your PC, pause running commands rather than ending them, and more.
A crashing program should be a rare occurrence, but if it’s happening more often than it should, it could point to a problem with your Ubuntu installation. You’ll need to look into some of the common reasons for Ubuntu crashes to (hopefully) resolve your issues.