Linux найти zombie процесс

How to find zombie process?

Surprising that no answer below actually says that there’s no zombie process in the system based on the above output. If there really was one, the ps auxwww | grep ‘Z’ command should have shown a process in a Z state. The «system information» saying => There is 1 zombie process. seems to be a bug. Either that, or there’s missing information in the question.

8 Answers 8

To kill a zombie (process) you have to kill its parent process (just like real zombies!), but the question was how to find it.

Find the zombie (The question answered this part):

What you get is Zombies and anything else with a Z in it, so you will also get the grep:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND usera 13572 0.0 0.0 7628 992 pts/2 S+ 19:40 0:00 grep --color=auto Z usera 93572 0.0 0.0 0 0 ?? Z 19:40 0:00 something 

Find the zombie’s parent:

init(1)---cnid_metad(1311)---cnid_dbd(5145) 

In this case you do not want to kill that parent process and you should be quite happy with one zombie, but killing the immediate parent process 5145 should get rid of it.

Additional resources on askubuntu:

The result you show in your answer is the the grep command itself, not the zombie process. It is the same mis-interpratation as Pablo made in his answer. The answer by Rinzwind below does actually look for the zombie process and list them. Another option could be to grep for «defunct»

This is a great answer! It is still valid today! I was able to find my zombie process and kill its parent process without any problems. Thank you!

Even though this question is old I thought everyone deserved a more reliable answer:

This will emit two whitespace-delimited columns, the first of which is a PID and the second of which is its state.

I don’t think even GNU ps provides a way to filter by state directly, but you can reliably do this with awk

You now have a list of PIDs which are zombies. Since you know the state it’s no longer necessary to display it, so that can be filtered out.

Giving a newline-delimited list of zombie PIDs.

You can now operate on this list with a simple shell loop

for pid in $(ps axo pid=,stat= | awk '$2~/^Z/ < print $1 >') ; do echo "$pid" # do something interesting here done 

ps is a powerful tool and you don’t need to do anything complicated to get process information out of it.

awk is also a powerful tool which doesn’t just split text but can also match it. +1 . the others used grep where it’s unnecessary and imprecise.

@chovy: It will depend, but generally involves killing or signalling the parent. Other answers here go in to that. From within the loop shown above you can find the parent pid like this: ps -p «$pid» -opid=,ppid=

Читайте также:  Astra linux common edition руководство администратора

if i will the parent won’t it kill all its child processes? I just want to kill the one zombie process. I know the ppid.

That’s like, give me a forest (tree) of all users’ processes in a user oriented format with unlimited width on any tty and show it to me at half a screen above where it matches the case that the 8th column contains a Z, and why not highlight the whole line.

User oriented format seems to mean: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND so the Zombie status will show up in the 8th column.

You can throw in an N before the p if you want line numbers, and a J if you want an asterisk at the match. Sadly if you use G to not highlight the line that asterisk will not show, though J creates space for it.

You end up getting something that looks like:

… root 2919 0.0 0.0 61432 5852 ? Ss Jan24 0:00 /usr/sbin/sshd -D root 12984 0.0 0.1 154796 15708 ? Ss 20:20 0:00 \_ sshd: lamblin [priv] lamblin 13084 0.0 0.0 154796 9764 ? S 20:20 0:00 \_ sshd: lamblin@pts/0 * lamblin 13086 0.0 0.0 13080 5056 pts/0 Z 20:20 0:00 \_ -bash lamblin 13085 0.0 0.0 13080 5056 pts/0 Ss 20:20 0:00 \_ -bash root 13159 0.0 0.0 111740 6276 pts/0 S 20:20 0:00 \_ su - nilbmal nilbmal 13161 0.2 0.0 13156 5004 pts/0 S 20:20 0:00 \_ -su nilbmal 13271 0.0 0.0 28152 3332 pts/0 R+ 20:20 0:00 \_ ps afuwwx nilbmal 13275 0.0 0.0 8404 848 pts/0 S+ 20:20 0:00 \_ less +u -Jp^(\S+\s+)Z.* … 

You could follow this up with (and it’ll detect if your terminal likes -U Unicode or -A Ascii):

OR just, you know, use the up-arrow in less to follow that tree/forest through the hierarchy; which is what I was recommending with the «Less is more» approach.

Источник

Ищем и убиваем zombie процессы

Apr 27, 2017 16:22 · 405 words · 2 minute read zombie defunct

Дочерний процесс в Unix-системе, завершивший своё выполнение, но ещё присутствующий в списке процессов операционной системы, чтобы дать родительскому процессу считать код завершения называют зомби (англ. zombie process, defunct process) — говорит нам Википедия.

Подробнее ознакомиться с возникновением зомби-процессов и связанными с ними проблемами можно на той же Wiki, а мы разберемся как вычислить такие процессы и “убить” их!

Найти zombie -процесс можно несколькими способами, например:

Итак, находим zombie -процессы в нашей системе:

ps aux | grep -w Z git 2512 0.6 0.0 0 0 ? Z 08:31 1:08 [grunt] git 3574 0.0 0.0 0 0 ? Z кві13 0:48 [grunt] root 12523 0.0 0.0 112652 1036 pts/5 S+ 11:22 0:00 grep --color=auto -w Z git 13855 0.3 0.0 0 0 ? Z 07:07 0:47 [grunt] git 14896 0.0 0.0 0 0 ? Z кві13 0:48 [grunt] git 16213 0.0 0.0 0 0 ? Z кві03 0:44 [grunt] git 24146 0.5 0.0 0 0 ? Z 07:49 1:11 [grunt] git 26321 0.0 0.0 0 0 ? Z кві13 0:47 [grunt] git 29765 0.5 0.0 0 0 ? Z 08:10 1:09 [grunt] git 32440 0.0 0.0 0 0 ? Z кві13 0:47 [grunt] 

“Убить” найденные zombie-процессы просто так не получится. Самый правильный вариант — найти родительский процесс и убить или перезапустить его. (Еще может помочь перезагрузка сервера, но это точно не наш путь). Находим родительские процессы (их PID’ы в третьей колонке):

ps ajx | grep -w Z  2475 2512 2427 2427 ? -1 Z 1004 1:08 [grunt]  3557 3574 3509 3509 ? -1 Z 1004 0:48 [grunt] 12350 12671 12671 12330 pts/5 12671 S+ 0 0:00 grep --color=auto -w Z 13839 13855 13791 13791 ? -1 Z 1004 0:47 [grunt] 14869 14896 14820 14820 ? -1 Z 1004 0:48 [grunt] 16192 16213 16144 16144 ? -1 Z 1004 0:44 [grunt] 24120 24146 24071 24071 ? -1 Z 1004 1:11 [grunt] 26290 26321 26236 26236 ? -1 Z 1004 0:47 [grunt] 29725 29765 29645 29645 ? -1 Z 1004 1:09 [grunt] 32423 32440 32375 32375 ? -1 Z 1004 0:47 [grunt] 

При желании можно узнать больше подробностей о родительском процессе, например так:

ps auxww | grep 32375 root 12689 0.0 0.0 112648 1016 pts/5 S+ 11:23 0:00 grep --color=auto 32375 git 32375 0.0 0.0 211180 2892 ? Ss кві13 0:00 git-receive-pack /home/git/repo/ed.git 

Дальше этот процесс можем просто “убить”:

Читайте также:  Кнопка пуск на линуксе

Источник

How to find and kill zombie processes in Linux

Zombie Processes

Before we get into the Zombie process, let me recall what a process is in Linux. In short, a process is a program instance. It can be foreground (interactive process) or background (non-interactive or automatic process). It can be a parent process (the creator of other processes at runtime) or a child process (a process created by other processes). In Linux, every process has a parent process, except for the first init (or systemd) process with a PID of 0. Processes also have their own child processes. Use the pstree command to view the process tree in the terminal, and also to view the “family” of system processes. In this tutorial we will explain how to find and kill zombie processes in Linux.

What is a zombie process in Linux?

When a child process dies, it notifies the parent process so that it can do some cleanup, such as freeing memory. However, if the parent process does not know of its death, the child process will enter the zombie state. For the parent process, the child process still exists, but the child process is effectively dead. This is how zombie processes (also known as dead processes) are created and remain in the system.

Do we need to worry about zombie processes?

Truth be told zombie processes are not as dangerous as their name sounds. Problems can occur if your system has limited memory or if there are too many zombie processes taking up memory. In addition, most Linux processes can have a maximum PID of 32768, and your system may crash if other processes do not have available IDs. This is rare, but it can happen, especially if a poorly coded program starts spawning a lot of zombie processes. In this case, it is best to find and kill the zombie processes.

How to find zombie processes?

  • D = uninterrupted sleep
  • I = idle
  • R = Running
  • S = Sleeping
  • T = Stopped by job control signal
  • t = Stopped by debugger during trace
  • Z = Zombie

But where can you see the processes and their respective status? An easy way is to use the terminal and top commands.

Читайте также:  Изменить имя пользователя astra linux

Linux top

As you can see in the screenshot above, there are a total of 250 tasks (or processes), 1 is running, 248 processes are dormant, and 1 is in a zombie state.

How do I find and kill a zombie process? Can zombie processes be killed?

A zombie process is already dead. How do you kill a process that is already dead?

In zombie movies, you can shoot a zombie in the head or set it on fire. But that’s not a good option here. You can burn your system to kill the zombie process, but that’s not a good solution 😉

Some people suggest to send SIGCHLD signal to the parent process. But it is more likely to be ignored. An alternative to killing a zombie process is to kill its parent process. This sounds cruel, but it is the only reliable way to kill a zombie process.

So, first, let’s list the zombie processes so we know their IDs, which can be done by using the ps command in the terminal.

Column 8 of the ps ux command output shows the status of the process. You are asked to print all matching rows for which the process status is Z+ (indicating zombie status).

After determining its process ID, let’s get its parent process ID.

Alternatively, you can combine the above two commands in the following way, which directly provides the PID of the zombie process and the PID of its parent process.

ps -A -ostat,pid,ppid | grep -e '[zZ]' 

Here you get the parent process ID, so finally you terminate the process by entering the corresponding ID process you got earlier in the command line.

linux kill

You can verify that the zombie process is killed by running the ps command again or even the top command.

Now you know how to get rid of zombie processes.

Источник

Зомби процессы Linux

Каждая программа, которая выполняется в Linux, — это системный процесс, у которого есть свой идентификатор. Каждый процесс может запускать дочерние процессы с помощью функции fork. Такие процессы остаются под контролем родительского процесса и не могут быть завершены без его ведома. Если один из дочерних процессов всё же завершился, а его родительский процесс не смог получить об этом информацию, то такой дочерний процесс становится зомби.

Зомби процессы Linux не выполняются и убить их нельзя, даже с помощью sigkill, они продолжают висеть в памяти, пока не будет завершён их родительский процесс.

Посмотреть такие процессы можно с помощью утилиты ps, здесь они отмечаются как defunct:

Если вы попытаетесь убить такой процесс с помощью сигнала KILL, то ничего не выйдет:

Чтобы его завершить, нужно найти «родителя» этого процесса. Для этого используйте команду:

Здесь идентификатор родительского процесса находится в четвёртой колонке (PPID). Теперь мы можем послать ему сигнал завершения, и такого процесса в системе больше не будет:

Для большего удобства вы можете использовать утилиты top или htop, но принцип их действия будет аналогичным, поэтому я не буду здесь его рассматривать. Теперь вы знаете, что делать, если в вашей системе появились зомби процессы Linux.

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

Оцените статью
Adblock
detector