Everyone knows how to kill a program using Task Manager on Windows or Force Quit on OS X, but sometimes it is helpful to kill a program using the command line. I ran into several situations where the program refused to exit through the task manager even when I tried to kill the underlying process. Force Quit has its quirks and doesn’t always kill the program the way it should. Then you can use the full power of the command line.
In this article, I will introduce the commands to shutdown the program on Windows, OS X and Linux. Interestingly, there are usually several commands used for this, so I’ll try to mention the different ones I used. This is not an exhaustive list, so if you are using another command not mentioned here please let us know in the comments.
Windows – TSKILL and TASKKILL
On Windows, you can use two commands to kill the program: TSKILL and TASKKILL. TSKILL is a simpler and less powerful command, but it does its job well. For example, if you are using Microsoft Word, the process name is winword.exe. To kill Word from the command line, simply enter the following command:
tskill winword
This will kill Word and you will lose all unsaved data, so you must be careful when using it. I tried it on an unsaved Word document and it just disappeared when I ran this, no prompts to save documents. This is pretty much true of all the commands I’m going to mention here, as it’s kind of a gist. You can kill the program instantly without asking questions.
It should be noted that in most cases this command is used with the / A. / A option instructs the command to end the process running in all sessions. Therefore, as a rule, you should enter the following command to be sure that the process is complete:
tskill / A winword
The second command, which has more parameters and is more powerful, is TASKKILL. If you look at the TASKKILL man page, you can see what I mean:
If you want more control and ability to uninstall a program in Windows, use TASKKILL. First, you can kill the program using the following command:
taskkill / F / IM winword.exe
Note that you must use .EXE when using the TASKKILL command. / F means force termination of the process. / IM stands for the name of the image, i.e. the name of the process. If you want to kill using the process id (PID) you need to use / PID instead of / IM. / T is great because it will kill all child processes started by the specified process.
You can also use TASKKILL to remotely connect to another system and terminate the process on that remote system. What I also like is the ability to use wildcards in TASKKILL.
OS X / Linux – kill and be killed
On OS X and Linux, you have two commands to kill processes: KILL and KILLALL. You must run them in a terminal window. To kill a program, you must use either the program name or the process ID. There are several ways to find this information. One way is through Activity Monitor.
However, this requires a graphical interface. If you are using the command line to kill a process, you can also use the command line to find information about the process. Two commands come to mind: top and ps -ax.
top will give you a list of processes with PID and program name, also sorted by CPU load. This is a quick way to find the process to kill. ps -ax will give you a list sorted by PID and program path. It is slightly different from the top one.
Now for the program termination in OS X. You can simply enter the following command to kill a specific process:
kill -9 83002
83002 is a terminal process, and 9 means it is destroyed. You can use other numbers, such as 3 for exit, or 6 for interrupt. However, in most cases you will stick with 9. You can also use the KILL command to kill all running processes, although you should probably never use this command.
kill -TERM -1
If KILL is used to kill one or all processes, KILLALL is used to kill the process group. For example, if you are using Google Chrome, you may have 10 Chrome processes running. It would be very frustrating to use KILL ten times to close Chrome. Instead, you can use KILLALL like this:
killall Evernote or killall ‘Google Chrome’
Please note that you must use single quotes or anything longer than one word. Also, if the process is not running under your name but instead is running as root, you should use the following command:
sudo killall ‘Google Chrome’
or
sudo killall -9 ‘Google Chrome’
Again, 9 sends a specific KILL signal, not TERM. Sudo is only required if you get a permission denied message. Otherwise, you can run the killall program or the killall -9 program. On OS X, the KILLALL command comes in very handy when you can’t force a program to close. You don’t need to know the process ID, which is good. Just enter a name and all processes associated with that name will be killed.
This article was intended to give you more advanced methods of killing a program on Windows, OS X and Linux. If you have any questions about uninstalling the program from the command line, please leave a comment and I will try to help. Enjoy!
–