One-by-one termination for sysrq.

Ben Clifford (benc@dass.prestel.co.uk)
Sun, 20 Jul 1997 22:45:43 +0000 (GMT)


This patch goes onto sysrq.c v1.4 and adds in key code 'n', for
terminate-oNe-by-one.

It sends SIGTERM to the process with the highest pid.

This allows you to terminate the last program you ran without messing up
things like daemons.

diff -urN kernels/2.1.46-pre1+benc/drivers/char/sysrq.c linux/drivers/char/sysrq.c
--- kernels/2.1.46-pre1+benc/drivers/char/sysrq.c Sat Jul 19 22:29:20 1997
+++ linux/drivers/char/sysrq.c Sun Jul 20 22:22:12 1997
@@ -6,6 +6,8 @@
*
* (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
* based on ideas by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>
+ * One-by-one termination added by Ben Clifford
+ * <benc@dass.prestel.co.uk>
*/

#include <linux/config.h>
@@ -50,6 +52,23 @@
}
}

+
+static int send_sig_highest(int sig)
+{
+ struct task_struct *p, *high=NULL;
+
+ for_each_task(p) {
+ if (NULL==high) high=p;
+ else if (p->pid > high->pid && p->mm != &init_mm) high=p;
+ }
+ if(high) {
+ force_sig(sig, high);
+ return high->pid;
+ }
+ else
+ return 0;
+}
+
/*
* This function is called by the keyboard handler when SysRq is pressed
* and any other keycode arrives.
@@ -118,6 +137,10 @@
orig_log_level = key - '0';
printk("Log level set to %d\n", orig_log_level);
break;
+ case 'n': /* N - terminate the highest pid */
+ printk("Terminate tasks one by one\n");
+ printk("Terminated %d\n",send_sig_highest(SIGTERM));
+ break;
case 'e': /* E -- terminate all user processes */
printk("Terminate All Tasks\n");
send_sig_all(SIGTERM, 0);
@@ -141,7 +164,7 @@
#ifdef CONFIG_APM
"Off "
#endif
- "Sync Unmount showPc showTasks showMem loglevel0-8 tErm Kill killalL\n");
+ "Sync Unmount showPc showTasks showMem loglevel0-8 tErm termoNe Kill killalL\n");
}

console_loglevel = orig_log_level;