为了能够找出哪个进程被linux OOMkiller杀死,我们将利用Linux提供给我们的grep命令。但首先我们需要了解grep命令是什么以及如何在 Linux 上使用它。
Linux 中的grep命令用于过滤文件中特定字符模式的搜索。它是最常用的 Linux 实用程序命令之一,用于显示包含我们尝试搜索的模式的行。
通常,我们尝试在文件中搜索的模式称为正则表达式。
grep [options] pattern [files]
虽然我们有很多不同的选择,但最常用的是: -
-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
现在,让我们考虑一种情况,我们希望在特定目录的所有文件中找到特定模式,比如 dir1。
grep -rni "word" *
在上面的命令中,将“word”占位符替换为
为此,我们使用如下所示的命令 -
grep -rni "func main()" *
上面的命令将尝试main()在特定目录和子目录中的所有文件中查找字符串“func ”。
输出结果
main.go:120:func main() {}
应该注意的是,存储有关被杀死进程信息的日志通常存在于 Linux 机器上的/var/log目录中。
为了检查哪些进程被杀死,我们可以使用如下所示的命令。
grep -i 'killed process' /var/log/syslog输出结果
[11686.043647] Killed process 2603 (ssrv) total-vm:149536kB, anon-rss:72174kB, file-rss:4228kB