home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 16845 < prev    next >
Encoding:
Text File  |  1992-11-16  |  12.9 KB  |  531 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!sybus.sybus.com!myrddin!tct!chip
  3. From: chip@tct.com (Chip Salzenberg)
  4. Subject: Re: FAQ: HERE IS ps patch for 0.98.4
  5. Message-ID: <2B07AC33.3F9E@tct.com>
  6. Date: Mon, 16 Nov 1992 14:12:03 GMT
  7. References: <2B0431C5.575D@tct.com>
  8. Organization: TC Telemanagement, Clearwater, FL
  9. Lines: 520
  10.  
  11. Earlier I posted...
  12. >See, I'm about to apply 0.98 patch 4, but I don't want to proceed
  13. >until I can patch my ps so it will work...
  14.  
  15. Here it is: the patch for ps-0.98 for use with Linux 0.98pl4.  Thanks
  16. to a nice person whose address I've lost (sorry).
  17.  
  18. ===============================================================================
  19. diff -c +recursive orig/ps-0.98/ps.c ps-0.98/ps.c
  20. *** orig/ps-0.98/ps.c    Tue Oct 20 13:38:26 1992
  21. --- ps-0.98/ps.c    Wed Nov  4 20:44:49 1992
  22. ***************
  23. *** 178,184 ****
  24.   show_procs()
  25.   {
  26.       struct task_struct *taskp;
  27. !     union task_union task_buf;
  28.       int tty, i, uid;
  29.       off_t _task = k_addr("_task");
  30.   
  31. --- 178,185 ----
  32.   show_procs()
  33.   {
  34.       struct task_struct *taskp;
  35. !     struct task_struct task_buf;
  36. !     char stack_buf[PAGE_SIZE];
  37.       int tty, i, uid;
  38.       off_t _task = k_addr("_task");
  39.   
  40. ***************
  41. *** 192,218 ****
  42.       if (taskp) {
  43.           kmemread(&task_buf, taskp, sizeof(task_buf));
  44.               /* check if valid, proc may have exited */
  45. !         if ((unsigned) task_buf.task.state > 4 ||
  46. !             task_buf.task.pid <= 0 && i != 0)
  47.           continue;
  48.   
  49.           if (pid >= 0) {
  50. !         if (task_buf.task.pid != pid)
  51.               continue;
  52.           } else if (ctty) {
  53. !         if (task_buf.task.tty != tty)
  54.               continue;
  55.           } else
  56. !         if (!all && task_buf.task.uid != uid ||
  57. !             !no_ctty && task_buf.task.tty == -1 ||
  58. !             run_only && task_buf.task.state != TASK_RUNNING &&
  59. !                 task_buf.task.state != TASK_UNINTERRUPTIBLE)
  60.               continue;
  61.   
  62. !         (fmt_fnc[fmt])(&task_buf);
  63.           if (fmt != PS_V && fmt != PS_M)
  64. !         show_time(&task_buf);
  65. !         printf("%s\n", cmd_args(&task_buf));
  66.       }
  67.       }
  68.   }
  69. --- 193,221 ----
  70.       if (taskp) {
  71.           kmemread(&task_buf, taskp, sizeof(task_buf));
  72.               /* check if valid, proc may have exited */
  73. !         if ((unsigned) task_buf.state > 4 ||
  74. !             (task_buf.pid <= 0 && i != 0) ||
  75. !             !task_buf.kernel_stack_page)
  76.           continue;
  77.   
  78.           if (pid >= 0) {
  79. !         if (task_buf.pid != pid)
  80.               continue;
  81.           } else if (ctty) {
  82. !         if (task_buf.tty != tty)
  83.               continue;
  84.           } else
  85. !         if (!all && task_buf.uid != uid ||
  86. !             !no_ctty && task_buf.tty == -1 ||
  87. !             run_only && task_buf.state != TASK_RUNNING &&
  88. !                 task_buf.state != TASK_UNINTERRUPTIBLE)
  89.               continue;
  90.   
  91. !         kmemread(&stack_buf, task_buf.kernel_stack_page, PAGE_SIZE);
  92. !         (fmt_fnc[fmt])(&task_buf,&stack_buf);
  93.           if (fmt != PS_V && fmt != PS_M)
  94. !         show_time(&task_buf, &stack_buf);
  95. !         printf("%s\n", cmd_args(&task_buf, &stack_buf));
  96.       }
  97.       }
  98.   }
  99. ***************
  100. *** 219,226 ****
  101.   
  102.   
  103.   
  104. ! show_short(task)
  105.   struct task_struct *task;
  106.   {
  107.       printf("%5d %s %s",
  108.       task->pid,
  109. --- 222,230 ----
  110.   
  111.   
  112.   
  113. ! show_short(task, stack)
  114.   struct task_struct *task;
  115. + reg_t * stack;
  116.   {
  117.       printf("%5d %s %s",
  118.       task->pid,
  119. ***************
  120. *** 228,235 ****
  121.       status(task));
  122.   }
  123.   
  124. ! show_long(task)
  125.   struct task_struct *task;
  126.   {
  127.       long ppid;
  128.   
  129. --- 232,240 ----
  130.       status(task));
  131.   }
  132.   
  133. ! show_long(task, stack)
  134.   struct task_struct *task;
  135. + reg_t * stack;
  136.   {
  137.       long ppid;
  138.   
  139. ***************
  140. *** 242,259 ****
  141.       ppid,
  142.       2 * PZERO - task->counter,    /* sort of priority */
  143.       PZERO - task->priority,        /* nice value */
  144. !     VSIZE(task),
  145.       task->rss * 4,
  146.       (task->state == TASK_INTERRUPTIBLE ||
  147.        task->state == TASK_UNINTERRUPTIBLE ||
  148.        Debug > 1 && task->state == TASK_STOPPED ? 
  149. !         wchan(task->tss.ebp, task) : ""),
  150.       status(task),
  151.       dev_to_tty(task->tty));
  152.   }
  153.   
  154. ! show_jobs(task)
  155.   struct task_struct *task;
  156.   {
  157.       long ppid, tpgid;
  158.       struct tty_struct *tt;
  159. --- 247,265 ----
  160.       ppid,
  161.       2 * PZERO - task->counter,    /* sort of priority */
  162.       PZERO - task->priority,        /* nice value */
  163. !     VSIZE(task,stack),
  164.       task->rss * 4,
  165.       (task->state == TASK_INTERRUPTIBLE ||
  166.        task->state == TASK_UNINTERRUPTIBLE ||
  167.        Debug > 1 && task->state == TASK_STOPPED ? 
  168. !         wchan(task->tss.ebp, stack) : ""),
  169.       status(task),
  170.       dev_to_tty(task->tty));
  171.   }
  172.   
  173. ! show_jobs(task, stack)
  174.   struct task_struct *task;
  175. + reg_t * stack;
  176.   {
  177.       long ppid, tpgid;
  178.       struct tty_struct *tt;
  179. ***************
  180. *** 284,291 ****
  181.       task->euid);
  182.   }
  183.   
  184. ! show_user(task)
  185.   struct task_struct *task;
  186.   {
  187.       time_t start;
  188.       int pcpu, pmem;
  189. --- 290,298 ----
  190.       task->euid);
  191.   }
  192.   
  193. ! show_user(task, stack)
  194.   struct task_struct *task;
  195. + reg_t * stack;
  196.   {
  197.       time_t start;
  198.       int pcpu, pmem;
  199. ***************
  200. *** 309,315 ****
  201.       task->pid,
  202.       pcpu / 10, pcpu % 10,
  203.       pmem / 10, pmem % 10,
  204. !     VSIZE(task),
  205.       task->rss * 4,
  206.       dev_to_tty(task->tty),
  207.       status(task),
  208. --- 316,322 ----
  209.       task->pid,
  210.       pcpu / 10, pcpu % 10,
  211.       pmem / 10, pmem % 10,
  212. !     VSIZE(task,stack),
  213.       task->rss * 4,
  214.       dev_to_tty(task->tty),
  215.       status(task),
  216. ***************
  217. *** 316,323 ****
  218.        ctime(&start) + (time_now - start > 3600*24 ? 4 : 10));
  219.   }
  220.   
  221. ! show_sig(task)
  222.   struct task_struct *task;
  223.   {
  224.       unsigned long sigignore=0, sigcatch=0, bit=1;
  225.       int i;
  226. --- 323,331 ----
  227.        ctime(&start) + (time_now - start > 3600*24 ? 4 : 10));
  228.   }
  229.   
  230. ! show_sig(task, stack)
  231.   struct task_struct *task;
  232. + reg_t * stack;
  233.   {
  234.       unsigned long sigignore=0, sigcatch=0, bit=1;
  235.       int i;
  236. ***************
  237. *** 341,348 ****
  238.       dev_to_tty(task->tty));
  239.   }
  240.   
  241. ! show_vm(task)
  242.   struct task_struct *task;
  243.   {
  244.       int pmem;
  245.   
  246. --- 349,357 ----
  247.       dev_to_tty(task->tty));
  248.   }
  249.   
  250. ! show_vm(task, stack)
  251.   struct task_struct *task;
  252. + reg_t * stack;
  253.   {
  254.       int pmem;
  255.   
  256. ***************
  257. *** 354,360 ****
  258.       printf(" %6d %4d %4d %4d ",
  259.       task->maj_flt + (Sum ? task->cmaj_flt : 0),
  260.       task->end_code / 1024,
  261. !     SIZE(task), task->rss*4);
  262.       if (task->rlim[RLIMIT_RSS].rlim_cur == RLIM_INFINITY)
  263.       printf("   xx ");
  264.       else
  265. --- 363,369 ----
  266.       printf(" %6d %4d %4d %4d ",
  267.       task->maj_flt + (Sum ? task->cmaj_flt : 0),
  268.       task->end_code / 1024,
  269. !     SIZE(task, stack), task->rss*4);
  270.       if (task->rlim[RLIMIT_RSS].rlim_cur == RLIM_INFINITY)
  271.       printf("   xx ");
  272.       else
  273. ***************
  274. *** 364,371 ****
  275.   }
  276.   
  277.   
  278. ! show_m(task)
  279.   struct task_struct *task;
  280.   {
  281.       int i;
  282.       unsigned long pagedir[0x300];
  283. --- 373,381 ----
  284.   }
  285.   
  286.   
  287. ! show_m(task, stack)
  288.   struct task_struct *task;
  289. + reg_t * stack;
  290.   {
  291.       int i;
  292.       unsigned long pagedir[0x300];
  293. ***************
  294. *** 431,438 ****
  295.       dt << pg_shift);
  296.   }
  297.   
  298. ! show_regs(task)
  299.   struct task_struct *task;
  300.   {
  301.       printf("%2d %5d %8x %8x %8x ",
  302.       task->start_code >> 26,
  303. --- 441,449 ----
  304.       dt << pg_shift);
  305.   }
  306.   
  307. ! show_regs(task, stack)
  308.   struct task_struct *task;
  309. + reg_t * stack;
  310.   {
  311.       printf("%2d %5d %8x %8x %8x ",
  312.       task->start_code >> 26,
  313. ***************
  314. *** 441,448 ****
  315.       task->start_code >> 16,
  316.       **/
  317.       task->start_stack,
  318. !     KSTK_ESP(task),
  319. !     KSTK_EIP(task));
  320.   
  321.       prtime(task->timeout, jiffies);
  322.       prtime(task->it_real_value, 0);
  323. --- 452,459 ----
  324.       task->start_code >> 16,
  325.       **/
  326.       task->start_stack,
  327. !     KSTK_ESP(stack),
  328. !     KSTK_EIP(stack));
  329.   
  330.       prtime(task->timeout, jiffies);
  331.       prtime(task->it_real_value, 0);
  332. ***************
  333. *** 487,494 ****
  334.   };
  335.   
  336.   
  337. ! show_time(task)
  338.   struct task_struct *task;
  339.   {
  340.       unsigned t;
  341.   
  342. --- 498,506 ----
  343.   };
  344.   
  345.   
  346. ! show_time(task, stack)
  347.   struct task_struct *task;
  348. + reg_t * stack;
  349.   {
  350.       unsigned t;
  351.   
  352. ***************
  353. *** 500,507 ****
  354.   }
  355.   
  356.   char *
  357. ! status(task)
  358.   struct task_struct *task;
  359.   {
  360.       static char buf[5] = "    ";
  361.   
  362. --- 512,520 ----
  363.   }
  364.   
  365.   char *
  366. ! status(task, stack)
  367.   struct task_struct *task;
  368. + reg_t * stack;
  369.   {
  370.       static char buf[5] = "    ";
  371.   
  372. diff -c +recursive orig/ps-0.98/ps.h ps-0.98/ps.h
  373. *** orig/ps-0.98/ps.h    Tue Sep 22 22:06:56 1992
  374. --- ps-0.98/ps.h    Wed Nov  4 20:44:49 1992
  375. ***************
  376. *** 21,42 ****
  377.   
  378.   #define    PAGE_MASK    0xfff
  379.   
  380. ! #define    KSTK_EIP(task)    (*((unsigned long *)(task)+1019))
  381. ! #define    KSTK_ESP(task)    (*((unsigned long *)(task)+1022))
  382.   
  383. ! #define    _SSIZE(task)    (TASK_SIZE - KSTK_ESP(task))
  384. ! #define    SSIZE(task)    (KSTK_ESP(task) ? _SSIZE(task) : 0)
  385. ! #define    VSIZE(task)    (((task)->brk + 1023 + SSIZE(task)) / 1024)
  386. ! #define    SIZE(task)    (((task)->brk - (task)->end_code + 1023 + \
  387. !               SSIZE(task)) / 1024)
  388.   
  389. ! typedef unsigned reg_t;
  390. ! union task_union {
  391. !     struct task_struct task;
  392. !     reg_t stack[PAGE_SIZE/4];
  393. ! };
  394.   
  395.   
  396.   char *find_func();
  397.   unsigned long k_addr();
  398. --- 21,37 ----
  399.   
  400.   #define    PAGE_MASK    0xfff
  401.   
  402. ! #define    KSTK_EIP(stack)    ((stack)[1019])
  403. ! #define    KSTK_ESP(stack)    ((stack)[1022])
  404.   
  405. ! #define    _SSIZE(stack)    (TASK_SIZE - KSTK_ESP(stack))
  406. ! #define    SSIZE(stack)    (KSTK_ESP(stack) ? _SSIZE(stack) : 0)
  407.   
  408. ! #define    VSIZE(task,stack) (((task)->brk + 1023 + SSIZE(stack)) / 1024)
  409. ! #define    SIZE(task,stack)  (((task)->brk - (task)->end_code + 1023 + \
  410. !               SSIZE(stack)) / 1024)
  411.   
  412. + typedef unsigned reg_t;
  413.   
  414.   char *find_func();
  415.   unsigned long k_addr();
  416. diff -c +recursive orig/ps-0.98/top.c ps-0.98/top.c
  417. *** orig/ps-0.98/top.c    Fri Oct 16 19:55:57 1992
  418. --- ps-0.98/top.c    Thu Nov  5 22:04:24 1992
  419. ***************
  420. *** 54,60 ****
  421.   char hdr[200];
  422.   char *title="TOP   by Roger Binns    Ps (c) 1992 Branko Lankester";
  423.   
  424. ! void do_it(struct task_struct *task, int num);
  425.   void do_key(char c);
  426.   char *cm, *clrtobot, *cl, *so, *se, *clrtoeol, *mb, *md, *us, *ue;
  427.   char *outp;
  428. --- 54,60 ----
  429.   char hdr[200];
  430.   char *title="TOP   by Roger Binns    Ps (c) 1992 Branko Lankester";
  431.   
  432. ! void do_it(struct task_struct *task, reg_t *stack, int num);
  433.   void do_key(char c);
  434.   char *cm, *clrtobot, *cl, *so, *se, *clrtoeol, *mb, *md, *us, *ue;
  435.   char *outp;
  436. ***************
  437. *** 424,430 ****
  438.   show_procs()
  439.   {
  440.       struct task_struct *taskp;
  441. !     union task_union task_buf;
  442.       int tty, i, uid;
  443.       off_t _task = k_addr("_task");
  444.   
  445. --- 424,431 ----
  446.   show_procs()
  447.   {
  448.       struct task_struct *taskp;
  449. !     struct task_struct task_buf;
  450. !     char stack_buf[PAGE_SIZE];
  451.       int tty, i, uid;
  452.       off_t _task = k_addr("_task");
  453.   
  454. ***************
  455. *** 436,450 ****
  456.       if (taskp) {
  457.           kmemread(&task_buf, taskp, sizeof(task_buf));
  458.               /* check if valid, proc may have exited */
  459. !         if ((unsigned) task_buf.task.state > 4 ||
  460. !             task_buf.task.pid <= 0 && i != 0)
  461.           continue;
  462. !         do_it((struct task_struct *)&task_buf, i);
  463.       }
  464.       }
  465.   }
  466.   
  467. ! void do_it(struct task_struct *task, int num)
  468.   {
  469.       unsigned t, i;
  470.           time_t now, start;
  471. --- 437,453 ----
  472.       if (taskp) {
  473.           kmemread(&task_buf, taskp, sizeof(task_buf));
  474.               /* check if valid, proc may have exited */
  475. !         if ((unsigned) task_buf.state > 4 ||
  476. !             task_buf.pid <= 0 && i != 0 ||
  477. !             !task_buf.kernel_stack_page)
  478.           continue;
  479. !         kmemread(&stack_buf, task_buf.kernel_stack_page, PAGE_SIZE);
  480. !         do_it(&task_buf, (reg_t *) &stack_buf, i);
  481.       }
  482.       }
  483.   }
  484.   
  485. ! void do_it(struct task_struct *task, reg_t *stack, int num)
  486.   {
  487.       unsigned t, i;
  488.           time_t now, start;
  489. ***************
  490. *** 495,502 ****
  491.           case P_NICE: sprintf(tmp, "%3d ", PZERO-task->priority); break;
  492.           case P_PAGEIN: sprintf(tmp, "%6d ", task->maj_flt+(Sum ? task->cmaj_flt : 0)); break;
  493.           case P_TSIZ: sprintf(tmp, "%5d ", task->end_code/1024); break;
  494. !         case P_DSIZ: sprintf(tmp, "%5d ", SIZE(task)); break;
  495. !         case P_SIZE: sprintf(tmp, "%5d ", VSIZE(task)); break;
  496.           case P_TRS: sprintf(tmp, "%4d ", TRS); break;
  497.           case P_SWAP: sprintf(tmp, "%4d ", SWAP); break;
  498.           case P_SHARE: sprintf(tmp, "%5d ", SHARE); break;
  499. --- 498,505 ----
  500.           case P_NICE: sprintf(tmp, "%3d ", PZERO-task->priority); break;
  501.           case P_PAGEIN: sprintf(tmp, "%6d ", task->maj_flt+(Sum ? task->cmaj_flt : 0)); break;
  502.           case P_TSIZ: sprintf(tmp, "%5d ", task->end_code/1024); break;
  503. !         case P_DSIZ: sprintf(tmp, "%5d ", SIZE(task,stack)); break;
  504. !         case P_SIZE: sprintf(tmp, "%5d ", VSIZE(task,stack)); break;
  505.           case P_TRS: sprintf(tmp, "%4d ", TRS); break;
  506.           case P_SWAP: sprintf(tmp, "%4d ", SWAP); break;
  507.           case P_SHARE: sprintf(tmp, "%5d ", SHARE); break;
  508. ***************
  509. *** 507,513 ****
  510.           case P_WCHAN: sprintf(tmp, "%-9.9s ", 
  511.                       (task->state == TASK_INTERRUPTIBLE ||
  512.                        task->state == TASK_UNINTERRUPTIBLE ? 
  513. !                         wchan(task->tss.ebp, task) : "")); break; 
  514.           case P_STAT: sprintf(tmp, "%-4.4s ", status(task)); break;
  515.           case P_TIME: sprintf(tmp, "%3d:%02d ", t/60, t%60); break;
  516.           case P_COMMAND: strcpy(tmp, cmd_args(task)); break; 
  517. --- 510,516 ----
  518.           case P_WCHAN: sprintf(tmp, "%-9.9s ", 
  519.                       (task->state == TASK_INTERRUPTIBLE ||
  520.                        task->state == TASK_UNINTERRUPTIBLE ? 
  521. !                         wchan(task->tss.ebp, stack) : "")); break; 
  522.           case P_STAT: sprintf(tmp, "%-4.4s ", status(task)); break;
  523.           case P_TIME: sprintf(tmp, "%3d:%02d ", t/60, t%60); break;
  524.           case P_COMMAND: strcpy(tmp, cmd_args(task)); break; 
  525. ===============================================================================
  526.  
  527. -- 
  528. Chip Salzenberg at Teltronics/TCT  <chip@tct.com>, <73717.366@compuserve.com>
  529.                  just another elitist Usenet administrator
  530.