Basically there are 4 ways de kill effectively a process en Linux: kill it by name, by specifying a part of the name, by PID, pointing to the process window with the mouse cursor. Let's see one by one ... |
Kill: kill a process using its PID
The most complicated but at the same time most accurate way of killing a process is through its PID ("Process Identifier"). Any of these 3 variants can serve:
kill -TERM pid kill -SIGTERM pid kill -15 pid
You can use the name of the signal (TERM or SIGTERM) that you want to send to the process or its identification number (15). To see a complete list of possible signals, I suggest checking the kill manual. To do this, run:
man kill
Let's see an example of how to kill Firefox:
First, you have to find out the PID of the program:
ps -ef | grep firefox
That command will return something like this:
1986? Sl 7:22 /usr/lib/firefox-3.5.3/firefox
We use the PID returned by the above command to kill the process:
kill-9 1986
killall: kill a process using its name
This command is very easy
killall process_name
One thing to keep in mind when using this method is that if there is more than one instance of that program running, they will all be closed.
pkill: kill a process using part of its name
It is possible to kill a process by specifying the full name or part of the name. That means there is no need for you to remember the process PID to send the signal.
pkill part_process_name
In return, this method will kill all processes that contain the word entered. That means that if we have 2 processes open that share a word in the name, both will be closed.
xkill: kill a process by selecting the window with the mouse
This is the simplest and most practical method. In the event of a disaster, simply press Alt + F2 to bring up the dialog box allowing you to run commands. From there, run the following command:
xkill
The mouse cursor will transform into a small skull. All that remains is to click on the window you want to close and voila. Bye process.
Some final comments
In closing, I wanted to share some tips that may be helpful. In Linux, as in Windows, when a process hangs, the window in question can generally be closed by clicking the Close button (which is shaped like an X). After a few seconds, a window will appear asking us if we really want to kill the process since it does not respond properly. We say yes and that's it.
This means that the methods described here should be used when nothing happens when you click the Close button of the window in question.
In case of major disaster, do not forget that before pressing it is possible to carry out a "safe" restart.
Finally, it can be very useful to find out which processes are currently running. For this, the different desktop environments (GNOME, KDE, etc.) have graphical tools that facilitate this task. However, in case you cannot access them or simply want to do it from the terminal, you can execute the following:
top
In case this doesn't work or you don't have the corresponding package installed, you can always run:
ps-A
This will list all the running processes, along with their respective names and PIDs.
«Ps -ef | grep firefox "is not the same as" pgrep firefox "?
Well personally I use "pidof" to get the PID.
Regards!
what I use the most is:
~ $ top
showing us the list of active processes, then if we hit "k" or write "kill" it will ask us for the pid of the process to kill (we read it from top) and then enter, to exit top we press "q".
Very good entry, but this form seems simpler to me. If the terminal does not run we try with ctrl + alt + f [1-6] and do it from there.
What geniuses guys thanks for helping me gave me a great hand with this post !!!
Hello! Could it be that the xkill command only makes the X program disappear and is still open? Because it always happens to me that when I go to the task manager the process is still alive and I have to kill it.
I admit it, I am a very newbie. And the killall and pkill commands are going to help me a lot. Thanks for uploading them, very good blog.
Regards!
I recommend htop 😀 it is the best for that ...
works with ncurses
sudo apt-get install htop
pidof is not for all Unixes, for example Solaris does not have that command, and that leads us to use the powerful ps.
regards
htop is more verbose and user friendly
In the case of using PID, the correct thing is $ kill PID that sends the SIGTERM signal by default, in case the process does not respond, $ kill -9 PID is used that sends the SIGKILL signal, the latter eliminates the process without letting it the same closure correctly (there may be data loss for example). SIGTERM asks please, SIGKILL gives him an ax 🙂
Thank you very much, I will test it if it happens to me again.
a query. When the desktop environment hangs in Ubuntu (I use Unity), can it be restarted without killing all other processes? I am not very advanced in linux and it happens to me sometimes that I am working and it hangs, the only thing I do is the safe restart, but I lose everything I was working on.
I don't know if my doubt is understood.
regards
A process in the zombie state cannot be killed in the traditional way.
Here for more details: esdebian.org/wiki/matar-proceso-zombie
For the more advanced, how do you kill a process in ZOMBIE state?
just to generate a little chat 😀
Very good, just what I needed ..
The truth is that the kill command is very useful. Being able to kill annoying processes just by invoking kill is great. Finally a command that serves something.
Theoretical question: Killing a process means that it stops working. So my question is the other way around, if I want to restart that process that I killed, how do I do it?
Well you put ./(the name of the process) &
With this you run it again and your PID will also come out 😀
Excellent, I had time looking for help like this. It was very useful to me. Thank you very much for sharing.
Greetings from San Luis Potosí, Mexico.
How can I kill two processes knowing their PID in the same command?
I think it was' kill [First PID] [Second PID]
Very interesting article. This website is my main linux website.
I generally use:
ps ax | grep process_name (this to locate it on the system)
kill -9 process_id
I share a free online bash course that goes around:
https://aprendemia.com/cursos/curso-de-bash-scripting Hopefully it will be useful.
and if I wanted it to be a profile in linux only the one that closes as it should be?
example I have 2 firefox profiles open
but I only want a single profile to close
1 profile
2 profile
I want only profile 2 to close as the command should be
in advance thanks for the answer
how can i kill ubuntu foreground processes, with a single command line