From: dbell@pdact.pd.necisa.oz.au (David I. Bell) Subject: ANNOUNCE: Updated patch for ^T status line in kernel Date: Fri, 30 Apr 1993 01:47:30 GMT
Here is an updated kernel patch for Linux 0.99.9 to implement my ^T status
feature. This patch is also useful for earlier versions of the kernel.
This version of the patch fixes several bugs that were in my first version.
This feature outputs a status line about the most recently running process
in your terminal group when a ^T is typed. The information gives the pid,
process name, size, runtime, number of page faults, pc, and its current
status (running or reason for sleeping). This output is very convenient
and unlike running ps, is immediate and does not affect swapping or
scheduling.
Since Alt-SysRq is now used for another purpose, the status feature is not
also tied to that key anymore, as it was in my first version of the patch.
-dbell-
#!/bin/sh
# This is a shell archive (shar 3.32)
# made 04/30/1993 01:21 UTC by dbell@elm
# Source directory /usr/users/dbell
#
# existing files WILL be overwritten
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 10502 -rw-r--r-- CTRLT.99.9.DIF
#
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= CTRLT.99.9.DIF ==============
echo "x - extracting CTRLT.99.9.DIF (Text)"
sed 's/^X//' << 'SHAR_EOF' > CTRLT.99.9.DIF &&
Xdiff --context --recursive linux-0.99.9.O/fs/buffer.c linux-0.99.9.N/fs/buffer.c
X*** linux-0.99.9.O/fs/buffer.c Mon Mar 22 10:40:20 1993
X--- linux-0.99.9.N/fs/buffer.c Thu Apr 29 20:29:12 1993
X***************
X*** 64,69 ****
X--- 64,70 ----
X add_wait_queue(&bh->b_wait, &wait);
X repeat:
X current->state = TASK_UNINTERRUPTIBLE;
X+ current->waitstr = "buffer wait";
X if (bh->b_lock) {
X schedule();
X goto repeat;
Xdiff --context --recursive linux-0.99.9.O/fs/inode.c linux-0.99.9.N/fs/inode.c
X*** linux-0.99.9.O/fs/inode.c Sat Apr 10 20:56:43 1993
X--- linux-0.99.9.N/fs/inode.c Thu Apr 29 20:29:12 1993
X***************
X*** 367,372 ****
X--- 367,373 ----
X add_wait_queue(&inode->i_wait, &wait);
X repeat:
X current->state = TASK_UNINTERRUPTIBLE;
X+ current->waitstr = "inode wait";
X if (inode->i_lock) {
X schedule();
X goto repeat;
Xdiff --context --recursive linux-0.99.9.O/fs/locks.c linux-0.99.9.N/fs/locks.c
X*** linux-0.99.9.O/fs/locks.c Sun Mar 7 10:30:01 1993
X--- linux-0.99.9.N/fs/locks.c Thu Apr 29 20:29:13 1993
X***************
X*** 153,158 ****
X--- 153,159 ----
X if (cmd == F_SETLKW) {
X if (current->signal & ~current->blocked)
X return -ERESTARTSYS;
X+ current->waitstr = "file lock";
X interruptible_sleep_on(&fl->fl_wait);
X if (current->signal & ~current->blocked)
X return -ERESTARTSYS;
Xdiff --context --recursive linux-0.99.9.O/fs/proc/array.c linux-0.99.9.N/fs/proc/array.c
X*** linux-0.99.9.O/fs/proc/array.c Sun Mar 7 19:07:16 1993
X--- linux-0.99.9.N/fs/proc/array.c Thu Apr 29 20:29:13 1993
X***************
X*** 349,354 ****
X--- 349,456 ----
X return count;
X }
X
X+
X+ /*
X+ * Print the status of the most recently running process in the specified
X+ * terminal's current process group to that terminal.
X+ */
X+ void
X+ show_proc_status(struct tty_struct *tty)
X+ {
X+ struct task_struct *p, **pp;
X+ unsigned long vsize;
X+ unsigned long pc;
X+ unsigned long runint;
X+ int runfrac;
X+ char *cp;
X+ char runstr[20];
X+ static char str[80];
X+
X+ p = NULL;
X+ for (pp = &LAST_TASK ; pp > &FIRST_TASK ; --pp) {
X+ if (!*pp || ((*pp)->pgrp != tty->pgrp))
X+ continue;
X+ if (!p || ((*pp)->runorder > p->runorder))
X+ p = *pp;
X+ }
X+ if (!p) {
X+ cp = "No processes in terminal's process group\r\n";
X+ goto store;
X+ }
X+ switch (p->state) {
X+ case TASK_RUNNING:
X+ if (p == current)
X+ cp = "running";
X+ else
X+ cp = "runable";
X+ break;
X+ case TASK_INTERRUPTIBLE:
X+ cp = "sleep";
X+ if (p->waitstr)
X+ cp = p->waitstr;
X+ break;
X+ case TASK_UNINTERRUPTIBLE:
X+ cp = "io wait";
X+ if (p->waitstr)
X+ cp = p->waitstr;
X+ break;
X+ case TASK_ZOMBIE:
X+ cp = "zombie";
X+ break;
X+ case TASK_STOPPED:
X+ cp = "stopped";
X+ break;
X+ case TASK_SWAPPING:
X+ cp = "swapping";
X+ break;
X+ default:
X+ cp = "unknown state";
X+ break;
X+ }
X+ runint = p->utime + p->stime;
X+ runfrac = ((runint % HZ) * 100) / HZ;
X+ runint /= HZ;
X+ if (runint < 60)
X+ sprintf(runstr, "%d.%02d", runint, runfrac);
X+ else if (runint < 60*60)
X+ sprintf(runstr, "%d:%02d.%02d", runint / 60, runint % 60,
X+ runfrac);
X+ else
X+ sprintf(runstr, "%d:%02d:%02d.%02d", runint / (60*60),
X+ (runint % (60*60)) / 60, runint % 60, runfrac);
X+
X+ vsize = 0;
X+ pc = 0;
X+ if (p->kernel_stack_page) {
X+ vsize = VSIZE(p, p->kernel_stack_page) / 1024;
X+ pc = KSTK_EIP(p->kernel_stack_page);
X+ }
X+
X+ sprintf(str, "pid %d (%s) cpu %s mem %d/%d pgft %d pc %x %s\r\n",
X+ p->pid,
X+ p->comm,
X+ runstr,
X+ p->rss * 4,
X+ vsize,
X+ p->maj_flt + p->min_flt,
X+ pc,
X+ cp);
X+ cp = str;
X+
X+ store: /*
X+ * Here to store a string into a terminal output buffer if it
X+ * will fit. This is not quite right, since newlines aren't
X+ * handled properly. This should really call a new routine in
X+ * tty_io which would do this correctly.
X+ */
X+ if (strlen(cp) > LEFT(&tty->write_q))
X+ return;
X+ while (*cp)
X+ put_tty_queue(*cp++, &tty->write_q);
X+ TTY_WRITE_FLUSH(tty);
X+ }
X+
X+
X static struct file_operations proc_array_operations = {
X NULL, /* array_lseek */
X array_read,
Xdiff --context --recursive linux-0.99.9.O/fs/select.c linux-0.99.9.N/fs/select.c
X*** linux-0.99.9.O/fs/select.c Thu Apr 15 23:32:10 1993
X--- linux-0.99.9.N/fs/select.c Thu Apr 29 20:29:13 1993
X***************
X*** 116,121 ****
X--- 116,122 ----
X wait = &wait_table;
X repeat:
X current->state = TASK_INTERRUPTIBLE;
X+ current->waitstr = "select wait";
X for (i = 0 ; i < n ; i++) {
X if (FD_ISSET(i,in) && check(SEL_IN,wait,current->filp[i])) {
X FD_SET(i, res_in);
Xdiff --context --recursive linux-0.99.9.O/fs/super.c linux-0.99.9.N/fs/super.c
X*** linux-0.99.9.O/fs/super.c Sat Apr 17 15:20:56 1993
X--- linux-0.99.9.N/fs/super.c Thu Apr 29 20:29:21 1993
X***************
X*** 56,61 ****
X--- 56,62 ----
X add_wait_queue(&sb->s_wait, &wait);
X repeat:
X current->state = TASK_UNINTERRUPTIBLE;
X+ current->waitstr = "superblock wait";
X if (sb->s_lock) {
X schedule();
X goto repeat;
Xdiff --context --recursive linux-0.99.9.O/include/linux/sched.h linux-0.99.9.N/include/linux/sched.h
X*** linux-0.99.9.O/include/linux/sched.h Fri Apr 16 10:55:27 1993
X--- linux-0.99.9.N/include/linux/sched.h Thu Apr 29 20:29:22 1993
X***************
X*** 160,165 ****
X--- 160,167 ----
X unsigned long start_code,end_code,end_data,brk,start_stack;
X unsigned long arg_start, arg_end, env_start, env_end;
X long pid,pgrp,session,leader;
X+ unsigned long runorder;
X+ char *waitstr;
X int groups[NGROUPS];
X /*
X * pointers to (original) parent process, youngest child, younger sibling,
X***************
X*** 227,232 ****
X--- 229,236 ----
X /* ec,brk... */ 0,0,0,0,0,0,0,0, \
X /* argv.. */ 0,0,0,0, \
X /* pid etc.. */ 0,0,0,0, \
X+ /* runorder */ 0, \
X+ /* wait str */ NULL, \
X /* suppl grps*/ {NOGROUP,}, \
X /* proc links*/ &init_task,&init_task,NULL,NULL,NULL, \
X /* uid etc */ 0,0,0,0,0,0, \
Xdiff --context --recursive linux-0.99.9.O/include/linux/tty.h linux-0.99.9.N/include/linux/tty.h
X*** linux-0.99.9.O/include/linux/tty.h Thu Apr 22 20:32:21 1993
X--- linux-0.99.9.N/include/linux/tty.h Thu Apr 29 20:29:25 1993
X***************
X*** 377,381 ****
X--- 377,385 ----
X
X extern int vt_ioctl(struct tty_struct *tty, struct file * file,
X unsigned int cmd, unsigned long arg);
X+ /* fs/proc/array.c */
X
X+ extern void show_proc_status(struct tty_struct *tty);
X+
X+
X #endif
Xdiff --context --recursive linux-0.99.9.O/kernel/blk_drv/ll_rw_blk.c linux-0.99.9.N/kernel/blk_drv/ll_rw_blk.c
X*** linux-0.99.9.O/kernel/blk_drv/ll_rw_blk.c Fri Mar 19 17:48:03 1993
X--- linux-0.99.9.N/kernel/blk_drv/ll_rw_blk.c Thu Apr 29 20:29:26 1993
X***************
X*** 196,201 ****
X--- 196,202 ----
X unlock_buffer(bh);
X return;
X }
X+ current->waitstr = "request wait";
X sleep_on(&wait_for_request);
X sti();
X goto repeat;
X***************
X*** 239,244 ****
X--- 240,246 ----
X if (req->dev<0)
X break;
X if (req < request) {
X+ current->waitstr = "request wait";
X sleep_on(&wait_for_request);
X goto repeat;
X }
X***************
X*** 369,374 ****
X--- 371,377 ----
X req->bh = NULL;
X req->next = NULL;
X current->state = TASK_UNINTERRUPTIBLE;
X+ current->waitstr = (rw == READ) ? "swap read" : "swap write";
X add_request(major+blk_dev,req);
X schedule();
X }
Xdiff --context --recursive linux-0.99.9.O/kernel/chr_drv/tty_io.c linux-0.99.9.N/kernel/chr_drv/tty_io.c
X*** linux-0.99.9.O/kernel/chr_drv/tty_io.c Thu Apr 22 20:21:02 1993
X--- linux-0.99.9.N/kernel/chr_drv/tty_io.c Thu Apr 29 20:29:31 1993
X***************
X*** 42,47 ****
X--- 42,48 ----
X #include <linux/mm.h>
X #include <linux/string.h>
X #include <linux/keyboard.h>
X+ #include <linux/config.h>
X
X #include <asm/segment.h>
X #include <asm/system.h>
X***************
X*** 646,651 ****
X--- 647,669 ----
X }
X continue;
X }
X+ /*
X+ * The process status character should really have
X+ * its own definition, but this requires changing
X+ * many user programs. As a partial solution, tie
X+ * it to the quit character, so if a program disables
X+ * quit, they also disable ^T. Programs that disable
X+ * quit probably want to disable all the other
X+ * special characters anyway.
X+ */
X+ #if CONFIG_PROC_FS
X+ if ((c == 'T'-'@') &&
X+ ((QUIT_CHAR(tty) != __DISABLED_CHAR)))
X+ {
X+ show_proc_status(tty);
X+ continue;
X+ }
X+ #endif
X }
X if (c==10 || (EOF_CHAR(tty) != __DISABLED_CHAR &&
X c==EOF_CHAR(tty)))
X***************
X*** 795,800 ****
X--- 813,819 ----
X if (!EMPTY(&tty->secondary))
X continue;
X current->state = TASK_INTERRUPTIBLE;
X+ current->waitstr = "tty input";
X if (EMPTY(&tty->secondary))
X schedule();
X current->state = TASK_RUNNING;
X***************
X*** 829,834 ****
X--- 848,854 ----
X add_wait_queue(&tty->secondary.proc_list, &wait);
X while (1) {
X current->state = TASK_INTERRUPTIBLE;
X+ current->waitstr = "tty input";
X if (available_canon_input(tty))
X break;
X if (current->signal & ~current->blocked)
X***************
X*** 876,881 ****
X--- 896,902 ----
X break;
X }
X current->state = TASK_INTERRUPTIBLE;
X+ current->waitstr = "tty output";
X if (FULL(&tty->write_q)) {
X TTY_WRITE_FLUSH(tty);
X if (FULL(&tty->write_q))
Xdiff --context --recursive linux-0.99.9.O/kernel/exit.c linux-0.99.9.N/kernel/exit.c
X*** linux-0.99.9.O/kernel/exit.c Wed Apr 14 15:05:35 1993
X--- linux-0.99.9.N/kernel/exit.c Thu Apr 29 20:29:33 1993
X***************
X*** 515,520 ****
X--- 515,521 ----
X if (options & WNOHANG)
X return 0;
X current->state=TASK_INTERRUPTIBLE;
X+ current->waitstr = "proc wait";
X oldblocked = current->blocked;
X current->blocked &= ~(1<<(SIGCHLD-1));
X schedule();
Xdiff --context --recursive linux-0.99.9.O/kernel/sched.c linux-0.99.9.N/kernel/sched.c
X*** linux-0.99.9.O/kernel/sched.c Fri Apr 23 23:52:29 1993
X--- linux-0.99.9.N/kernel/sched.c Thu Apr 29 20:29:33 1993
X***************
X*** 46,51 ****
X--- 46,52 ----
X
X static unsigned long init_kernel_stack[1024];
X static struct task_struct init_task = INIT_TASK;
X+ static unsigned long runcounter;
X
X unsigned long volatile jiffies=0;
X unsigned long startup_time=0;
X***************
X*** 138,149 ****
X--- 139,155 ----
X (*p)->priority;
X }
X sti();
X+ if (next) {
X+ task[next]->runorder = ++runcounter;
X+ task[next]->waitstr = NULL;
X+ }
X switch_to(next);
X }
X
X int sys_pause(void)
X {
X current->state = TASK_INTERRUPTIBLE;
X+ current->waitstr = "paused";
X schedule();
X return -ERESTARTNOHAND;
X }
SHAR_EOF
$TOUCH -am 0430192993 CTRLT.99.9.DIF &&
chmod 0644 CTRLT.99.9.DIF ||
echo "restore of CTRLT.99.9.DIF failed"
set `wc -c CTRLT.99.9.DIF`;Wc_c=$1
if test "$Wc_c" != "10502"; then
echo original size 10502, current size $Wc_c
fi
exit 0