How to find out which process was killed by Linux OOM killer?


In order to be able to find out which process was killed by linux OOM killer, we will make use of the grep command that Linux provides us with. But at first we need to understand what a grep command is and how to use it on Linux.

The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It is one of the most used Linux utility commands to display the lines that contain the pattern that we are trying to search.

Normally, the pattern that we are trying to search in the file is referred to as the regular expression.

Syntax

grep [options] pattern [files]

While there are plenty of different options available to us, some of the most used are: −

-c : It lists only a count of the lines that match a pattern
-h : displays the matched lines only.
-i : Ignores, case for matching
-l : prints filenames only
-n : Display the matched lines and their line numbers.
-v : It prints out all the lines that do not match the pattern

Now, let’s consider a case where we want to find a particular pattern in all the files in a particular directory, say dir1.

Syntax

grep -rni "word" *

In the above command replace the “word” placeholder with

For that, we make use of the command shown below −

grep -rni "func main()" *

The above command will try to find a string “func main()” in all the files in a particular directory and also in the subdirectories as well.

Output

main.go:120:func main() {}

It should be noted that the logs that store the information about the processes that were killed are usually present inside the /var/log directory on your Linux machine.

In order to check what processes were killed, we can make use of the command shown below.

Command

grep -i 'killed process' /var/log/syslog

Output

[11686.043647] Killed process 2603 (ssrv) total-vm:149536kB, anon-rss:72174kB, file-rss:4228kB

Updated on: 29-Jul-2021

670 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements