写在前面
本篇基于cgroup memory子系统的内存实现对oom_kill查杀事件的监控和上报。
一、内存炸弹程序
oomkill_bomber.c
#include <stdio.h> /* for printf */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h> /* for parse command parameters */
#define KB (1024)
#define MB (1024 * KB)
#define GB (1024 * MB)
/*
struct option {
//name of long option
const char *name;
//one of no_argument, required_argument, and optional_argument:
//whether option takes an argument
int has_arg;
//if not NULL, set *flag to val when option found
int *flag;
//if flag not NULL, value to set *flag to; else return value
int val;
};*/
int main(int argc, char *argv[])
{
char *p;
int c;
int size = 0;
int option_index = 0;
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"gb", required_argument, NULL, 'g'},
{"
|