How to force kill process in Linux using kill and killall
How to force kill process in Linux
- Use pidof command to find the process ID of a running program or app
pidoff appname - To kill process in Linux with PID:
kill -9 pid - To kill process in Linux with application name:
killall -9 appname
How to Kill a Process in Linux
Let us try to kill a process that is called firefox. To find firefox pid run any one of the following commands:
pidof firefox
pgrep firefox
ps aux | grep firefox
Locating the process (PID) to kill on Linux
Force kill process on Linux command line
To kill process on Linux use the kill command:
kill pid
kill -SIGKILL pid
kill 27707
By default signal 15, named SIGTERM, is sent to kill process. Hence all of the following are doing same things:
kill -15 27707
kill -SIGTERM 27707
kill 27707
Verify that firefox process gone:
pidof firefox
pgrep firefox
ps aux | grep firefox
There are many signals that can be used with kill, but, most users will only need to be aware of signal 9 and 15. To get full list, run:
kill -l
Sample outputs:
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
How to Kill a Process in Linux using SIGKILL
Sometime -SIGTERM (-15) fails, the stronger signal 9, called SIGKILL, should be used for force killing of process. For example, the following command would guarantee that process 27707 would be killed:
kill -9 27707
kill -SIGKILL 27707
Linux force kill process using killall command
Instead of using PID one can kill any process by name using the killall or pkill command. The syntax is:
killall -9 app
pkill -9 app
The killall command sends a signal to all processes running any of the specified commands. For example, forcefully kill all nginx process, run:
killall -9 nginx
You may want to run the killall command as root user to kill process of all users on Linux:
sudo killall -9 nginx
It is also possible to kill process with confirmation:
killall -9 vim
How to kill processes older than TIME
Want to kill a process called vim that has been running for more than 24 hours? Try:
killall -o 24h appName
killall -o 24h vim
The time is specified as a float then a unit. The units are:
Unit | Meaning |
---|---|
s | seconds |
m | minutes |
h | hours |
d | days |
w | weeks |
M | Months |
y | years |
How to kill processes younger than TIME
Let us kill a process that has been running for less than 60 minutes:
killall -y 60 -9 appName
killall -y 60 -9 firefox
How to kill only process(es) running as USER
Say you want to kill vim process that in running as vivek user, run:
killall -u
killall -u vim -9 vim
Conclusion
This page showed how to use the kill and killall commands on Linux operating systems to terminate processes forcefully.
Убиваем процессы в Linux — команды ps, kill и killall
Под процессом мы будем понимать запущенную в системе копию программы. Например, если вы открыли три окна калькулятора (например, gcalctool), это значит, что вы запустили три процесса.
Находим PID зависшего процесса
Каждый процесс в Linux имеет свой идентификатор, называемый PID. Перед тем, как выполнить остановку процесса, нужно определить его PID. Для этого воспользуемся командами ps и grep. Команда ps предназначена для вывода списка активных процессов в системе и информации о них. Команда grep запускается одновременно с ps (в канале) и будет выполнять поиск по результатам команды ps. Вывести список всех процессов можно, выполнив в командной строке:
Но, как правило, список очень большой и найти процесс, который мы хотим «убить», бывает не так просто. Здесь на помощь приходит команда grep. Например, чтобы найти информацию о процессе с именем gcalctool выполните команду:
Команда grep выполнит поиск по результатам команды ps и на экран будут выведены только те строки, которые содержат строку (слово) gcalctool. Здесь есть одна интересная деталь, например, если у вас не запущено приложение gcalctool, то после выполнения ps axu | grep gcalctool вы получите:
То есть мы получили сам процесс grep, так как в качестве параметра команде мы указали слово gcalctool, и grep нашел сам себя в выводе команды ps.
Если процесс gcalctool запущен, то мы получим:
Здесь нас интересует строка: «yuriy 25609 7.6 0.4 500840 17964 ? Sl 10:20 0:00 gcalctool». Число 25609 и есть идентификатор (PID) процесса gcalctool.
Есть еще один более простой способ узнать PID процесса — это команда pidof, которая принимает в качестве параметра название процесса и выводит его PID. Пример выполнения команды pidof:
«Убиваем» процесс командой kill
Когда известен PID процесса, мы можем убить его командой kill. Команда kill принимает в качестве параметра PID процесса. Например, убьем процесс с номером 25609:
Вообще команда kill предназначена для посылки сигнала процессу. По умолчанию, если мы не указываем какой сигнал посылать, посылается сигнал SIGTERM (от слова termination — завершение). SIGTERM указывает процессу на то, что необходимо завершиться. Каждый сигнал имеет свой номер. SIGTERM имеет номер 15. Список всех сигналов (и их номеров), которые может послать команда kill, можно вывести, выполнив kill -l. Чтобы послать сигнал SIGKILL (он имеет номер 9) процессу 25609, выполните в командой строке:
Сигнал SIGTERM может и не остановить процесс (например, при перехвате или блокировке сигнала), SIGKILL же выполняет уничтожение процесса всегда, так как его нельзя перехватить или проигнорировать.
Убиваем процессы командой killall
Команда killall в Linux предназначена для «убийства» всех процессов, имеющих одно и то же имя. Это удобно, так как нам не нужно знать PID процесса. Например, мы хотим закрыть все процессы с именем gcalctool. Выполните в терминале:
Команда killall, также как и kill, по умолчанию шлет сигнал SIGTERM. Чтобы послать другой сигнал нужно воспользоваться опцией -s. Например:
Заключение
Некоторые процессы не удается остановить под обычным пользователем. Например, если процесс был запущен от имени пользователя root или от имени другого пользователя системы, то команды kill и killall нужно выполнять от имени суперпользователя, добавляя sudo (в Ubuntu):
Бывают ситуации, когда вы работаете в графическом интерфейсе (например, GNOME) и вам не удается открыть эмулятор терминала, чтобы остановить зависший процесс. Тогда можно переключиться на виртуальную консоль клавишами Ctrl+Alt+F1, залогиниться в ней и выполнять команды уже из нее. А потом перейти обратно, нажав Ctrl+Alt+F7.
Справку по использованию любой команды можно получить командой man:
Kill Process in Linux or Terminate a Process in UNIX / Linux Systems
I am a new Linux system user. How do I kill a process on Linux based server using command line options? How can I kill running process on Unix?
Linux and Unix-like operating system come with the kill command to terminate stalled or unwanted processes without having to log out or restart the server. Hence, it is important to the stability of Linux systems. The kill command sends the designated signal such as KILL process to the specified process or process groups. If no signal is specified, the TERM signal is sent. Please note that kill command can be internal as part of modern shells built-in function or externally located at /bin/kill. Usage and syntax remain similar regardless internal or external kill command.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | kill |
Time | 10 minutes |
A list of common Linux or Unix TERM signals
Linux and Unix-like operating system support the standard terminate signals listed below:
- SIGHUP (1) – Hangup detected on controlling terminal or death of controlling process. Use SIGHUP to reload configuration files and open/close log files.
- SIGKILL (9) – Kill signal. Use SIGKILL as a last resort to kill process. It will not save data or cleaning kill the process.
- SIGTERM (15) – Termination signal. It is the default and safest way to kill process.
The kill and killall command support more than 60 signals. However, most users only need to use signal 9 or 15. To get a full list of signals, type:
kill -l
What is a PID?
A Linux or Unix process is running instance of a program. For example, Firefox is a running process if you are browsing the Internet. Each time you start Firefox browser, the system is automatically assigned a unique process identification number (PID). A PID is automatically assigned to each process when it is created on the system. To find out PID of firefox or httpd process use the following pidof command:
pidof httpd pidof apache2 pidof firefox
OR use the combination of ps command and grep command/egrep command:
ps aux | grep httpd ps aux | grep apache2 ps aux | grep firefox
Fig.01: Find the process ID (PID) of a running firefox program and apache2 server.
pgrep command
You can use pgrep command to find process ID (PID) too:
pgrep process
pgrep firefox
pgrep vim
How to kill process in Linux from the command line
kill -[signal] PID kill -15 PID kill -9 PID kill -SIGTERM PID kill [options] -SIGTERM PID
What Linux or Unix permissions do I need to kill a process?
- You can kill all your own process.
- Only root user can kill system level process.
- Only root user can kill process started by other users.
kill command examples to kill a process on Linux
In this example, I am going to kill lighttpd server process.
Step 1 – Find out the PID (process id) of the lighttpd
Use the ps or pidof command to find out PID for any program. For example, if process name is lighttpd, you can use any one of the following command to obtain process ID:
pidof lighttpd
Sample outputs:
OR
ps aux | grep lighttpd
Sample outputs:
Step 2 – kill the process using a PID
The PID # 3486 is assigned to the lighttpd process. To kill the lighttpd server, you need to pass a PID as follows:
# kill 3486
OR
$ sudo kill 3486
This will terminate a process with a PID of 3486.
How do I verify that the process is gone/killed?
Again use the ps command or pid command or pgrep command as follows:
$ ps aux | grep lighttpd
$ pidof lighttpd
$ pgrep lighttpd
A note about sending stronger signal # 9 (SIGKILL)
If no signal specified in the kill command, signal # 15 (SIGTERM), is sent by default. So the kill 3486 command is same as the following command:
# kill -15 3486
# kill -SIGTERM 3486
OR
$ sudo kill -15 3486
$ sudo kill -SIGTERM 3486
Sometime signal # 15 is not sufficient. For example, lighttpd may not be killed by signal #15 due to open sockets. In that case process (PID) # 3486 would be killed with the powerful signal # 9:
# kill -9 3486
# kill -SIGKILL 3486
OR
$ sudo kill -9 3486
$ sudo kill -SIGKILL 3486
Where,
- -9 or -SIGKILL – A special kill signal that nearly guarantee to kill the process with the iron fist.
How do I kill two or more Linux PIDs?
The syntax is as follows to kill two or more PIDs as required can be used in a single command:
kill pid1 pid2 pid3 kill -15 pid1 pid2 pid3 kill -9 pid1 pid2 pid3 kill -9 3546 5557 4242
Say hello to killall command
The killall is a Linux only command. It may be available on FreeBSD and other Unix like systems such as macOS to kill processes by name. So no need to find the PIDs using the ‘pidof process’ or ‘ps aux | grep process’ commands. Do not use the killall command on Solaris Unix operating systems. The syntax is:
To kill the lighttpd server, enter:
# killall -15 lighttpd
OR
# killall -9 lighttpd
To kill the Firefox web-browser process, enter:
# killall -9 firefox-bin
As I said earlier, the killall command on UNIX-like system does something else. It kills all process and not just specific process. Do not use killall on UNIX system. See your local man page for more info by typing the man command:
man killall
how to kill a process using system call?
Kill are of two types:
1.Graceful Kill
kill -15 pid
2.Forcible Kill
Kill pid. This format wont work.. Just check it..
These kill differs in releasing resources forcibly or gracefully……….
Kill PID works for me im running Debian 7 Wheezy…
some pid need root so su -c ‘kill pid’ will work
it work for me on fedora 24
I login as root, kill -9 a process but it refuses to stop. Is there a more powerful command?
use top command it will list the running processes dynamically then press “K” it will ask for process ID(PID) so enter the PID of the process you want to kill.
Ganesh
the kill pid works fine if u’re logged in as the root.
Also if you’re logged in with the user who started the process…
I tried to kill a process by kill -9 PID in user as well root mode. But it could not kill the process. What is another way to force kill?
Is the process changing PID after your kill -9 command? Because if it does it means it is a new process. This usually happens with apps that are beeing watched by some other process that will respawn the dead process.
To kill such a process you first need to find out what are the means used to respawn it and act accordingly. A “ps axf” will show you the relationship between processes. If the preocess you try to kill is a child of other process then it is most likely that the parent is respawning the child. So you will need to kill that process first. Otherwise, kill -9 used as root is “invincible” 🙂
I know parent of all process is init and its PID is zero. Can i kill pid zero? What happend to the system if i kill pid zero?
Init pid is not zero. init have pid 1
Swapper has pid of zero
I have a process that will not respond to any kill signal, nor can bash suspend it, nor did it react on removal of the USB device it was trying to access. I’m told it could be a buggy driver holding a global semaphore or “oopsed”, whatever that is. I guess there are some things that only a reboot will fix. 🙂
If it is respawning based on an entry in your inittab then you can modify the inittab (eg. remark the entry out) then issue :
telinit is linked to init and the q flag tells init to re-examine the inittab file.
i have inserted a pendrive in suse linux sp10. when i try to remove the pen drive the dialog displays device busy and shows its process id. every time i use the command kill -9 pid .
how can i avoid this?
When ever you insert you pen-drive to your system, it gets mounted in a particular directory, by default it mounts in /media in most OS. It is quite possible that you have not unmounted that pen-drive from that directory to which it has mounted.
Thanks for this tuto, is simple and easy to use
thank you, it works…
I got a window I cannot close, it is on top and I cannot access to the menus. I cannot move it either, the cursor cannot be moved outseide that window. So the only way to close the application should be a key combination, isn’t it? But which? (BTW, I’m a complete newbie, trying Ubuntu for the first time)
Anybody can guide me how can I kill time based processes? for example I want to kill processes that are 1 day old.
I was having this same problem. I know you must have use the man and got frustrated after “killall -o 1d” didn’t work. It turns out that the important thing that we missed was that TIME must be a string. In other words …. “killall -o 1.0d”
That works .
Dear I have a question.
Suppose i have a function that does some calculations.Well what i want to do,I want to stop the calculations in that function after some time (suppose 5 seconds).I really appreciate if anybody guides me in this regard.
“nice” is how nice a process is. The higher the number, it will tend to let other processes use CPU more. If negative, it has higher priority that other processes. Zero (0) is normal. See “man renice” to see how to change the “nice” value.
Dear Shivin,
The Init is the parent of all the process.The PID no is always One (1).
It’s an Parent of all the process so we called PPID.
All the runlevels are run under init.So it’s look like parent of all the runlevels.
If you kill the init ,then how it works…?
Thanks & Regards,
EverFriendly Naveen
If someone kill the init process, will the run labels work? Will the other processes not effected ??
Is there any other method?
Dear Shivin,
The root PID is zero (0)
Run this command it will show
pidof root
pidof init
The root is an User.The User informtions are stored in /etc/passwd file
in this file show
username,password,userid,groupid,gecos field,home directory,shelltype
The third field denotes the UID of the User.
Thanks & Regards,
Ever Friendly Naveen
Nice Article.
Thanks.
how kill command proceed.
iam getting this errror plz…. help me
[xsxsx@ip-111-111-11-111 javautils]$ kill 20073-bash: kill: (20073) – No such process
Please try to kill forcefully as:
$kill -9 20073
This usually means exactly what the message says: there is no process with that id running. This may be due to short lived processes or simply a typo in the command line
If you’re shore that you’ve seen a process with that PID, it may have died/ended on it’s own before you could type the command. You can check if a process is alive with “ps -e” (without the quotes) and looking at the list, or just “ps -e|grep 12345” to see if a process with PID 12345 exists or not. Note that every time you start an application, it will get a different PID. So if you killed a broken MPlayer or VLC (for example), when you start it again it will have another PID. If you start two instances of it, each will have it’s own PID. Also, the same PID my accidentally later be given to a completely different application. So never remember PID of given process by long term means.
I am using the
sudo killall -u root
as root but once all the machines have been killed the command will not end/terminate I have to go in and click the stop button.
Following a few of the commands, the kill -9 or kill -15 PID did not work for me, because it kept changing, like mircea had mentioned, it apparently was attached to another process. However, nobody told me how to find the other process…so I used the sudo killall -u root, mentioned by jw tech, and all it did was log me out of my session, however, for some reason it also killed the USB, because the mouse and keyboard did not respond.
Had to manually turn machine off…waste of time, I could have turned off machine from beginning!
Any other step-by-step commands for newbies like me?
Let meknow: sonhadorpr_at_gmail_dot_com
killall -u root is only usefull if you’re trying to shutdown the machine “gently” as it kills everything it can.
Use “$ ps -ejH” to display all processes in a tree. You might want to also “$ ps -ejH>tempprocesseslist;gedit tempprocesseslist;rm tempprocesseslist” to view the files nicely. Use ‘kate’, ‘mousepad’, ‘vi’, ‘nano’ or whatever instead of ‘gedit’ if you like/need.
Btw, don’t type/copy-paste the quotes and the $ sign ^^.
Now if you’re killing a process but it jumps back, maybe try killing/debugging it’s parent instead. Parent processes are those to the left (with less spacing at the left side) in the “tree”.
Explanation:
‘$ ps -ejH’
Displays all processes in a tree. This part is almost absolutely harmless (it takes up a lot of screen space). Use shift+pageUp/pageDown to scroll through the list if you’re stuck in CTRL+ALF+F1-6.
‘$ ps -ejH>tempprocesseslist’
Outputs to a file named ‘tempprocesseslist’ instead of screen. You can use any other filename istead of ‘tempprocesseslist’, but than you must use the same one in all three commands.
‘$ ps -ejH>tempprocesseslist;gedit tempprocesseslist’
Also open the file in text editor.
‘$ ps -ejH>tempprocesseslist;gedit tempprocesseslist;rm tempprocesseslist’
Also remove the file after it is no longer needed.
I like to get a tree view before killing off a process. Graphics make me happy 🙂 and also useful when the process table is a bit too complex to grasp.
If I want to kill firefox (No offence mozilla ;), this is what I use:
pstree -p | grep fire*
Then I would kill it using:
kill -9 28060
Exactly what I needed to kill a troublesome process on my old Clark Connect box!
Thanks!
Hey, you can also use grep command for killing the processes and ls is best known utility for this.
“grep” doesn’t kill a process, it is only used to filter output of other commands such as “ps” or “pstree”, at least in this context.
“ls” has practically absolutely nothing to do with killing a process. It is used to list segments (usually files) in a directory.
What Suse Linux permissions do I need to kill a process?
I’m not 100% sure as I’m not a Suse user, but this should do if you don’t have permissions to kill it:
$ su
Password:
# ps -e|grep part-of-process-name
# kill -9 PID
# exit
$ echo continue with what you were doing
Where PID is process ID (that number). You can use ‘pstree’ instead of ‘ps -e|grep blah’ if you want.
how can i kill safari?
OK. Here’s step-by-step how to kill anything.
Open a terminal (Konsole, Terminal, xterm, gnome-terminal, or press CTRL+ALT+F1*). Don’t type in the $ and # signs. Those indicate the beginning of a line which you have to type. *You can use any key from F1 to F6 here. Press CTRL+ALT+F7 to go back to the GUI.
Type:
$ ps -e
If you don’t see the whole list, you can scroll up and down with SHIFT+PAGE_UP and SHIFT+PAGE_DOWN.
Find the process’ number and type:
$ kill 12345
Where 12345 is the number of your process.
If it didn’t die, type:
$ kill -9 12345
Where 12345 is the process’ number.
If it still didn’t die, type:
$ su
# kill -9 12345
# exit
You can also use:
$ sudo su
instead of “$ su” if you don’t know/have the root password but you happen to be a sudo-er.
If it still didn’t die, type:
$ pstree
Now find process’ parent process (the one to the left of it), and repeat everything for the parent process.
Warning: don’t try killing “gdm”, “kdm”, “xdm” or “init” unless you really know what you’re doing.
You can also use:
$ pkill fullprocessname
instead of
$ kill processnumber
You can usually see the full process’ name in the “pstree” and “ps -e”, next to it’s number.
If you want to kill all instances of something, type:
$ killall fullprocessname
Full process name may be different from the program’s name, for example firefox’s full process name may be “firefox-bin” instead of just “firefox”.
Both pkill and killall can use -9 parameter as well. This parameter tells it to kill forcefully (and not gently). For example:
$ pkill -9 firefox-bin
$ killall -9 npviewer.bin
many thanks
do you know how can i remove an application using unix command?
What is the method used for killing init process using kill command?
During shutdown of the system, the init process is killed by the kernel , I want to know is their any method to kill it using kill command so that i can shutdown my computer on killing the init process.
So alt+sysrq+o shuts down the system.
Otherwise init always has PID 1, so “sudo kill -9 1” or “sudo pkill -9 init” or “sudo killall -9 init” will kill init abruptly. Use -15 instead of -9 or omitt it completely to do it more “gently”, although kill init itself isn’t very gentle method >_ Anonymous Apr 2, 2010 @ 12:10
what is force killing of process?how can it be done?
Thanks a lot! That is what I’ve been looking for half a year since started playing Nexuiz – it tends to block Gnome sometimes when i try to shut it down, killall didn’t help, now -9 parameter did the job. Before I got here, I had to restart X server using Ctrl+Alt+BckSpc and I was unable to save mo work in other programs. Now i just go: Ctrl+Alt+F1, username, password, killall -9 nexuiz. Thanks again! Terminal rocks 😀
I have a PHP CLI script on a UNIX machine that gets terminated after some time.
How to check if a process is terminated ? where do i look for to check if the process received a termination message ?
The script is to run for about 5 hrs how do i achieve this.
i am currently using php script_name.php
I have read about nohup but is nohup immune to Kill command.
I think someone either the administrator or the OS is killing the process. Is this possible, if so how do i stop this and make my script run for longer time.
“As I said earlier killall on UNIX system does something else. It kills all process and not just specific process. Do not use killall on UNIX system (use kill -9).”
This is inaccurate.
Mac OS X, one of the nine certified UNIX03 (which, despite the designation, is the current standard) operating systems, uses an implementation of killall which behaves as it does in Linux.
I’m not pointing this out to be pedantic, it saves keystrokes over the “(find the process’ #pid) `kill -9 #pid`” routine.
How do i kill a program, cleanly. I used killall on transmission, but everytime it starts, it goes on to verify the files. Thanks.
how can i kill ‘inside a script’ my other terminal (having open 2 terminals) and find which is the other one too. tnx 🙂
I am using sify internet. they provided one 24online client software for login. it is binary which directly run with help of user name. when 1st time I tried it asks me dns. It create conf file and I got massage that I logged in. for week I used same command like: ./crclient -u xyz123 and I get connected to internet. one day I was connected to internet lost connection due to electricity. I use to logout command like ./crclient -l. I tried to login and getting massage that
already logedin process id 2951. if I see process using ps -el of pgrep 2951 there is no process. I tried many things like shut down pc. reboot, kept for week off, but still same massage comming from. also I tried to do like install again. I could not understand if there is no process running then why it is saying that it is running. can any one help to stop it.
How to find out which process is not running?
It may be using pid file stored in /var/run directory.
kill -9 `ps ux | awk ‘/java/ && !/awk/
replace the word java with wather is your process name
There are two types of processes kill can’t remove: Immortal and Zombie, as explained in this note:
For those who don’t read technical stuff well, it basically says, iirc, a zombie is a child that has died, but not yet reaped by its parent. It uses no resources other than its process entry. Since the zombie is essentially dead, it cannot be killed again. If the parent itself dies before reaping the zombie, the child becomes an orphan and reparented to ‘init’ (the parent of almost all processes). When init waits for its children to die, it will also reap orphaned and its own zombie processes. Zombies are therefor dead processes waiting to be reaped by their parent/init. They should not exist for very long, seldom long enough for ps to list them.
An Immortal process is one that cannot be signalled because it has a priority higher than the signaling threshold: It won’t get signals sent by kill. Processes that use system critical resources (such as a disk drive) are temporarily given higher priority and therefore cannot be killed while accessing those resources. If the process waits for input from the resource, such as ‘transfer completed’, which never arrives because the devices was removed (for example), then the process can wait forever and becomes Immortal.
Now, if the parent is an Immortal process, and its child dies (either naturally or via the kill command), the child becomes both a zombie and immortal. It cannot be killed because it is already dead, it exists to be reaped. Its parent will never reap it and can’t be killed because it is blocked by system critical resources and won’t get any signals. Neither can init reap the zombie as an orphan because the parent still exists, and, kill can only kill live processes, not dead ones, so it can’t remove the zombie. Neither can kill remove the parent because the kernel (linux) won’t pass signals to it.
The only solution in this case is to reboot.
The difference between a respawned process (one that re-appears after being killed) and a zombie, is that the respawned process will (normally) have a different pid, while the zombie pid will always be the same. If it is a zombie, then the parent should reap it, otherwise go after the parent (ppid). If init is the parent and not reaping the zombie, it probably isn’t healthy and needs attention.
The difference between a Zombie and an Immortal process is that the zombie is dead and holds no resources, while an Immortal process has a high priority that prevents it from getting signals, is alive, and holding/consuming resources. Both zombie and immortal processes retain their pid after being ‘killed’.
Mostly, kill works just fine to remove buggy programs, but its the stubborn zombies and (more importantly) immortals where kill fails. I suspect the reason is that kill does not actively kill anything, but passively sends signals, assuming the target will ‘do the right thing’. For zombies and Immortals, they can’t or won’t. Apparently there is no nuke to smash these processes and mark all their resources as ‘available’. Perhaps a reboot is safer than risking the kernel screwing up its resource allocations and (silently) trashing system/user data?
I did find your article informative, the pidof with kill is exactly what I’ve been looking for. The answer to killing zombies and immortals is not what I wanted, but at least I know I’m not missing something (am I?).
hai,
i am first time using linux,please tell me all the commands for linux and main usage for current process for killing.
Anyone knows how to kill all the processes from a specific username from TOP command? Usually you have to indicate the PID, but i would like to kill all the PIDs from a user.