Skip to content

Instantly share code, notes, and snippets.

@virusdefender
Created March 18, 2018 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virusdefender/f494feb00f039bf6b97b49acbd29f564 to your computer and use it in GitHub Desktop.
Save virusdefender/f494feb00f039bf6b97b49acbd29f564 to your computer and use it in GitHub Desktop.
reset_proc_memory.c
#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>
int main(){
struct rusage usage;
while (1) {
getrusage(RUSAGE_SELF, &usage);
printf("%lld\n", usage.ru_maxrss);
fflush(NULL);
sleep(5);
}
}
obj-m += reset_proc_memory.o
KDIR ?= /lib/modules/$(shell uname -r)/build
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched/signal.h>
void reset(void)
{
struct task_struct* task;
for_each_process(task) {
// TODO lock
task->signal->cmaxrss = 0;
task->signal->maxrss = 0;
}
}
int init_module(void)
{
reset();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment