linux - [Solved-5 Solutions] Who “Killed” my process and why? - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

Find out who killed a process in Linux ?

Linux - Solution 1:

  • If the user or sysadmin did not kill the program the kernel may have.
  • The kernel would only kill a process under exceptional conditions, for example extreme resource starvation (think mem+swap exhaustion).

Linux - Solution 2:

  • When a process requests for more space, Linux will give it that space, even if it is claimed by another process, under the assumption that no one really uses all of the memory they request.
  • The process will get exclusive use of the memory it has allocated when it actually uses it, not when it asks for it.
  • This makes allocation quick, and might allow you to "cheat" and allocate more memory than you really have.
  • However, once processes start utilizing this memory, Linux may realize that it has been too generous in allocating memory it doesn't have, and will have to kill off a process to free some up.
  • The process to be killed depends on a score taking into account runtime , memory usage , and a few other factors, including a value you can adjust to make a process less likely to be killed

Linux - Solution 3:

Try:

dmesg | grep -E -i -B100 'killed process'
click below button to copy the code. By - Linux tutorial - team

Where -B100 signifies the number of lines before the kill happened.

Linux - Solution 4:

  • If you have 512 RAM + 1GB Swap memory. Your CPU has access to total of 1.5GB of virtual memory.
  • Now, for some time everything is running fine within 1.5GB of total memory. But all of sudden your system has started consuming more and more memory and it reached at a point around 95% of total memory used.
  • Now say any process has requested large chunck of memory from the kernel.
  • Kernel check for the available memory and find that there is no way it can allocate your process more memory.
  • So it will try to free some memory calling/invoking OOMKiller
  • OOMKiller has its own algorithm to score the rank for every process. Typically which process uses more memory becomes the victim to be killed.

Where can you find logs of OOMKiller?

Typically in /var/log directory. Either /var/log/kern.log or /var/log/dmesg

Some typical solutions:

  • Increase memory (not swap)
  • Find the memory leaks in your program and fix them
  • Restrict memory any process can consume (for example JVM memory can be restricted using JAVA_OPTS)
  • See the logs and google

Linux - Solution 5:

There are several ways:

  • Give your system more RAM if you can (easy if its a VM)
  • Make sure the OOM killer chooses a different process.
  • Disable the OOM Killer
  • Choose a Linux distro which ships with the OOM Killer disabled.

Related Searches to - linux - linux tutorial - Who “Killed” my process and why?