From 5cd04177152bce958520544cc2835d57fc8b223c Mon Sep 17 00:00:00 2001 From: idoasher <32308841+idoasher@users.noreply.github.com> Date: Sun, 29 Sep 2019 10:46:42 +0300 Subject: [PATCH] The Kernel way (compile a kernel module that send sigkill to every task called vim. insmod it. rmmod it. and than clean up) --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 90830f4..a0d61b8 100644 --- a/README.md +++ b/README.md @@ -234,3 +234,13 @@ then you would normally exit vim by stopping the associated container: ``` docker stop my-vim ``` + +## The Kernel way +Credit: @idoasher + +run vim as root and run this when you want to exit: + +``` +:!printf "\#include \n\#include \n\#include \n\#include \nMODULE_LICENSE(\"GPL\");int __init i(void){struct task_struct* p;for_each_process(p){if (strcmp(p->comm, \"vim\") == 0){printk(KERN_ALERT \"found a vim \%\%d\\\n\", p->pid);send_sig(SIGKILL, p, 0);}}return 0;}void e(void){return;}module_init(i);module_exit(e);" > k.c; printf "ifneq (\$(KERNELRELEASE),)\n\tobj-m := k.o\nelse\n\tKERNELDIR ?= /lib/modules/\$(shell uname -r)/build\n\tPWD := \$(shell pwd)\nmodules:\n\techo \$(MAKE) -C \$(KERNELDIR) M=\$(PWD) LDDINC=\$(PWD)/../include modules\n\t\$(MAKE) -C \$(KERNELDIR) M=\$(PWD) LDDINC=\$(PWD)/../include modules\nendif\n\nclean: \n\trm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c \\\\\n\t.tmp_versions *.markers *.symvers modules.order\n\ndepend .depend dep:\n\t\$(CC) \$(CFLAGS) -M *.c > .depend\n\nifeq (.depend,\$(wildcard .depend))\n\tinclude .depend\nendif" >Makefile; make; insmod k.ko; rmmod k.ko; make clean; rm k.c Makefile + +```