]> granicus.if.org Git - procps-ng/commitdiff
ps: add k and -x
authoralbert <>
Mon, 26 Apr 2004 00:47:31 +0000 (00:47 +0000)
committeralbert <>
Mon, 26 Apr 2004 00:47:31 +0000 (00:47 +0000)
NEWS
minimal.c
ps/common.h
ps/global.c
ps/help.c
ps/output.c
ps/parser.c
ps/sortformat.c

diff --git a/NEWS b/NEWS
index 3656a5e154275f30b6223721e7d878b551326683..e3b0c92ee06e6dbfaa8ff0e67e7ef8f30db4ccf7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 procps-3.2.1 --> procps-3.2.2
 
 avoid warning about -lncurses when not linking -- thanks FLWM
+ps: personality-specific -x support (HP-UX and SVR4-MP)
+ps: k option, same as --sort
 
 procps-3.2.0 --> procps-3.2.1
 
index f94f47ffb5e3435ee44865664c2fc2738be2e796..6c86c887bb56ee0c313201a66d084c14877e27f0 100644 (file)
--- a/minimal.c
+++ b/minimal.c
 #include <fcntl.h>
 #include <dirent.h>
 
+
+#define DEV_ENCODE(M,m) ( \
+  ( (M&0xfff) << 8)   |   ( (m&0xfff00) << 12)   |   (m&0xff)   \
+)
+
+///////////////////////////////////////////////////////
 #ifdef __FreeBSD__
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <sys/stat.h>
 #include <sys/proc.h>
 #include <sys/user.h>
+#define NO_TTY_VALUE DEV_ENCODE(-1,-1)
+#define HZ 1    // only bother with seconds
 #endif
 
+///////////////////////////////////////////////////////
 #ifdef __linux__
 #include <asm/param.h>  /* HZ */
 #include <asm/page.h>   /* PAGE_SIZE */
+#define NO_TTY_VALUE DEV_ENCODE(0,0)
+#ifndef HZ
+#warning HZ not defined, assuming it is 100
+#define HZ 100
+#endif
 #endif
 
-static int P_euid;
-static int P_pid;
+///////////////////////////////////////////////////////////
+
+#ifndef PAGE_SIZE
+#warning PAGE_SIZE not defined, assuming it is 4096
+#define PAGE_SIZE 4096
+#endif
+
+
+
+static char P_tty_text[16];
 static char P_cmd[16];
 static char P_state;
-static int P_ppid, P_pgrp, P_session, P_tty, P_tpgid;
+static int P_euid;
+static int P_pid;
+static int P_ppid, P_pgrp, P_session, P_tty_num, P_tpgid;
 static unsigned long P_flags, P_min_flt, P_cmin_flt, P_maj_flt, P_cmaj_flt, P_utime, P_stime;
 static long P_cutime, P_cstime, P_priority, P_nice, P_timeout, P_alarm;
 static unsigned long P_start_time, P_vsize;
@@ -56,6 +80,7 @@ static unsigned P_signal, P_blocked, P_sigignore, P_sigcatch;
 static unsigned long P_wchan, P_nswap, P_cnswap;
 
 
+
 #if 0
 static int screen_cols = 80;
 static int w_count;
@@ -79,16 +104,6 @@ static int thisarg;    /* index into ps_argv */
 static char *flagptr;  /* current location in ps_argv[thisarg] */
 
 
-#ifndef PAGE_SIZE
-#warning PAGE_SIZE not defined, assuming it is 4096
-#define PAGE_SIZE 4096
-#endif
-
-#ifndef HZ
-#warning HZ not defined, assuming it is 100
-#define HZ 100
-#endif
-
 
 
 static void usage(void){
@@ -334,8 +349,28 @@ static int stat2proc(int pid) {
        &P_euid, &P_euid   // don't know which is which
     );
 /*    fprintf(stderr, "stat2proc converted %d fields.\n",num); */
-    // convert FreeBSD tty numbers to Linux format :-)
-    P_tty = ((tty_min&0xfff00)<<12) | ((tty_maj&0xfff)<<8) | (tty_min&0xff) ;
+
+    snprintf(P_tty_text, sizeof P_tty_text, "%3d,%-3d", tty_maj, tty_min);
+    P_tty_num = DEV_ENCODE(tty_maj,tty_min);
+// tty decode is 224 to 256 bytes on i386
+#if 1
+    tmp = NULL;
+    if (tty_maj ==  5) tmp = " ttyp%c ";
+    if (tty_maj == 12) tmp = " ttyv%c ";
+    if (tty_maj == 28) tmp = " ttyd%c ";
+    if (P_tty_num == NO_TTY_VALUE) tmp = "   ?   ";
+    if (P_tty_num == DEV_ENCODE(0,0)) tmp = "console";
+    if (P_tty_num == DEV_ENCODE(12,255)) tmp = "consolectl";
+    if (tmp) {
+      snprintf(
+        P_tty_text,
+        sizeof P_tty_text,
+        tmp,
+        "0123456789abcdefghijklmnopqrstuvwxyz"[tty_min&31]
+      );
+    }
+#endif
+
     if(num < 9) return 0;
     if(P_pid != pid) return 0;
     return 1;
@@ -374,7 +409,7 @@ static int stat2proc(int pid) {
        "%u %u %u %u " /* no use for RT signals */
        "%lu %lu %lu",
        &P_state,
-       &P_ppid, &P_pgrp, &P_session, &P_tty, &P_tpgid,
+       &P_ppid, &P_pgrp, &P_session, &P_tty_num, &P_tpgid,
        &P_flags, &P_min_flt, &P_cmin_flt, &P_maj_flt, &P_cmaj_flt, &P_utime, &P_stime,
        &P_cutime, &P_cstime, &P_priority, &P_nice, &P_timeout, &P_alarm,
        &P_start_time, &P_vsize,
@@ -386,6 +421,14 @@ static int stat2proc(int pid) {
 /*    fprintf(stderr, "stat2proc converted %d fields.\n",num); */
     P_vsize /= 1024;
     P_rss *= (PAGE_SIZE/1024);
+
+    memcpy(P_tty_text, "   ?   ", 8);
+    if (P_tty_num != NO_TTY_VALUE) {
+      int tty_maj = (P_tty_num>>8)&0xfff;
+      int tty_min = (P_tty_num&0xff) | ((P_tty_num>>12)&0xfff00);
+      snprintf(P_tty_text, sizeof P_tty_text, "%3d,%-3d", tty_maj, tty_min);
+    }
+
     if(num < 30) return 0;
     if(P_pid != pid) return 0;
     return 1;
@@ -441,11 +484,9 @@ static const char *do_stime(void){
 }
 
 static void print_proc(void){
-  char tty[16];
-  snprintf(tty, sizeof tty, "%3d,%-3d", (P_tty>>8)&0xfff, (P_tty&0xff) | ((P_tty>>12)&0xfff00));
   switch(ps_format){
   case 0:
-    printf("%5d %s %s", P_pid, tty, do_time(P_utime+P_stime));
+    printf("%5d %s %s", P_pid, P_tty_text, do_time(P_utime+P_stime));
     break;
   case 'o':
     printf("%d\n", P_pid);
@@ -456,39 +497,39 @@ static void print_proc(void){
       "%5ld %06x %s %s",
       P_state, P_euid, P_pid, P_ppid, do_cpu(0),
       (int)P_priority, (int)P_nice, P_vsize/(PAGE_SIZE/1024),
-      (unsigned)(P_wchan&0xffffff), tty, do_time(P_utime+P_stime)
+      (unsigned)(P_wchan&0xffffff), P_tty_text, do_time(P_utime+P_stime)
     );
     break;
   case 'f':
     printf(
       "%8s %5d %5d %s %s %s %s",
-      do_user(), P_pid, P_ppid, do_cpu(0), do_stime(), tty, do_time(P_utime+P_stime)
+      do_user(), P_pid, P_ppid, do_cpu(0), do_stime(), P_tty_text, do_time(P_utime+P_stime)
     );
     break;
   case 'j':
     printf(
       "%5d %5d %5d %s %s",
-      P_pid, P_pgrp, P_session, tty, do_time(P_utime+P_stime)
+      P_pid, P_pgrp, P_session, P_tty_text, do_time(P_utime+P_stime)
     );
     break;
   case 'u'|0x80:
     printf(
       "%8s %5d %s %s %5ld %4ld %s %c %s %s",
-      do_user(), P_pid, do_cpu(1), do_mem(1), P_vsize, P_rss, tty, P_state,
+      do_user(), P_pid, do_cpu(1), do_mem(1), P_vsize, P_rss, P_tty_text, P_state,
       do_stime(), do_time(P_utime+P_stime)
     );
     break;
   case 'v'|0x80:
     printf(
       "%5d %s %c %s %6d   -   - %5d %s",
-      P_pid, tty, P_state, do_time(P_utime+P_stime), (int)P_maj_flt,
+      P_pid, P_tty_text, P_state, do_time(P_utime+P_stime), (int)P_maj_flt,
       (int)P_rss, do_mem(1)
     );
     break;
   case 'j'|0x80:
     printf(
       "%5d %5d %5d %5d %s %5d %c %5d %s",
-      P_ppid, P_pid, P_pgrp, P_session, tty, P_tpgid, P_state, P_euid, do_time(P_utime+P_stime)
+      P_ppid, P_pid, P_pgrp, P_session, P_tty_text, P_tpgid, P_state, P_euid, do_time(P_utime+P_stime)
     );
     break;
   case 'l'|0x80:
@@ -496,7 +537,7 @@ static void print_proc(void){
       "0 %5d %5d %5d %3d %3d "
       "%5ld %4ld %06x %c %s %s",
       P_euid, P_pid, P_ppid, (int)P_priority, (int)P_nice,
-      P_vsize, P_rss, (unsigned)(P_wchan&0xffffff), P_state, tty, do_time(P_utime+P_stime)
+      P_vsize, P_rss, (unsigned)(P_wchan&0xffffff), P_state, P_tty_text, do_time(P_utime+P_stime)
     );
     break;
   default:
@@ -544,7 +585,7 @@ int main(int argc, char *argv[]){
       if(want_one_command){
         if(strcmp(want_one_command,P_cmd)) continue;
       }else{
-        if(!select_notty && P_tty==-1) continue;
+        if(!select_notty && P_tty_num==NO_TTY_VALUE) continue;
         if(!select_all && P_euid!=ouruid) continue;
       }
       found_a_proc++;
index 2a919366c28072fcc406e6c1ffab3d8a31c616e8..1151451c69b46a54d8486780b645121cab142608 100644 (file)
 #define PER_NO_DEFAULT_g  0x0080
 #define PER_ZAP_ADDR      0x0100
 #define PER_SANE_USER     0x0200
+#define PER_HPUX_x        0x0400
+#define PER_SVR4_x        0x0800
 
 /* Simple selections by bit mask */
 #define SS_B_x 0x01
index cfb0aa5db400023a1c61aa837454e0bedad35455..8ca7cc19f68e38853b566de11714bb6fa13a1b60 100644 (file)
@@ -171,6 +171,7 @@ static const char *set_personality(void){
   {"sgi",      &&case_sgi},
   {"solaris2", &&case_solaris2},
   {"sunos4",   &&case_sunos4},
+  {"svr4",     &&case_svr4},
   {"sysv",     &&case_sysv},
   {"tru64",    &&case_tru64},
   {"unix",     &&case_unix},
@@ -304,10 +305,17 @@ static const char *set_personality(void){
 
   case_hp:
   case_hpux:
-  case_posix:
+    personality = PER_BROKEN_o | PER_HPUX_x;
+    return NULL;
+
+  case_svr4:
+  case_sysv:
   case_sco:
+    personality = PER_BROKEN_o | PER_SVR4_x;
+    return NULL;
+
+  case_posix:
   case_solaris2:
-  case_sysv:
   case_unix95:
   case_unix98:
   case_unix:
index 65686aaee2d8f49a41d0ad26c505fb1804aff085..dc2baa7bafe994e2bfed2a1163dfca8106652f0d 100644 (file)
--- a/ps/help.c
+++ b/ps/help.c
@@ -13,9 +13,6 @@
  * The help message must not become longer, because it must fit
  * on an 80x24 screen _with_ the error message and command prompt.
  */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
 
 const char *help_message =
 "********* simple selection *********  ********* selection by list *********\n"
index 8f9494d392cbffd177aeb092ad8201d834f9f239..b33745dfe3ef8d3525a5b50c65cd57aed2de5ae5 100644 (file)
@@ -38,9 +38,6 @@
  *
  * Table 5 could go in a file with the output functions.
  */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
  
 #include <ctype.h>
 #include <fcntl.h>
index 8bb81d616221b88c71c32c3d8b46d130a79044f6..f59ed8f053445a2bef6cc4044e6440e2f35877dd 100644 (file)
@@ -12,9 +12,6 @@
 /* Ought to have debug print stuff like this:
  * #define Print(fmt, args...) printf("Debug: " fmt, ## args)
  */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -432,12 +429,20 @@ static const char *parse_sysv_option(void){
       trace("-w wide output.\n");
       w_count++;
       break;
-#ifdef NOBODY_HAS_BSD_HABITS_ANYMORE
-    case 'x':     /* Same as -y, but for System V Release 4 MP */
-      trace("-x works like Sun Solaris & SCO Unixware -y option\n");
-      format_modifiers |= FM_x;
-      break;
-#endif
+    case 'x':  /* behind personality until "ps -ax" habit is uncommon */
+      if(personality & PER_SVR4_x){
+        // Same as -y, but for System V Release 4 MP
+        trace("-x works like Sun Solaris & SCO Unixware -y option\n");
+        format_modifiers |= FM_y;
+        break;
+      }
+      if(personality & PER_HPUX_x){
+        trace("-x extends the command line\n");
+        w_count += 2;
+        unix_f_option = 1;
+        break;
+      }
+      return "Must set personality to get -x option.";
     case 'y':  /* Sun's -l hack (also: Irix "lnode" resource control info) */
       trace("-y Print lnone info in UID/USER column or do Sun -l hack.\n");
       format_modifiers |= FM_y;
@@ -445,7 +450,7 @@ static const char *parse_sysv_option(void){
 #if 0
     case 'z':     /* alias of Mandatory Access Control level info */
       trace("-z shows aliased MAC info\n");
-      return "Don't understand MAC on Linux.";
+      return "Don't understand MAC aliases on Linux.";
       break;
 #endif
     case '-':
@@ -601,11 +606,16 @@ static const char *parse_bsd_option(void){
       trace("j job control format\n");
       format_flags |= FF_Bj;
       break;
-#if 0
-    case 'k':    // OpenBSD: don't hide "kernel threads" -- like the swapper?
-      trace("k Print LWP (thread) info.\n");   // was: Use /vmcore as c-dumpfile\n");
-      break;
-#endif
+    case 'k':
+      // OpenBSD: don't hide "kernel threads" -- like the swapper?
+      // trace("k Print LWP (thread) info.\n");   // was: Use /vmcore as c-dumpfile\n");
+
+      // NetBSD, and soon (?) FreeBSD: sort-by-keyword
+      trace("k Specify sorting keywords.\n");
+      arg=get_opt_arg();
+      if(!arg) return "Long sort specification must follow 'k'.";
+      defer_sf_option(arg, SF_G_sort);
+      return NULL; /* can't have any more options */
     case 'l':
       trace("l Display long format\n");
       format_flags |= FF_Bl;
@@ -1178,6 +1188,11 @@ try_bsd:
   // get seriously confused. Ask yourself if users would freak out
   // about "ps -aux" suddenly changing behavior if a user "x" were
   // added to the system.
+  //
+  // Also, a "-x" option is coming. It's already there in fact,
+  // for some non-default personalities. So "ps -ax" will parse
+  // as SysV options... and you're screwed if you've been patching
+  // out the friendly warning. Cut-over is likely to be in 2005.
   if(!(personality & PER_FORCE_BSD))
     fprintf(stderr, "Warning: bad syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html\n");
   // Remember: contact albert@users.sf.net or procps-feedback@lists.sf.net
index a7bfe43bfd2e8755943cc26eee162c2927913edf..4dbae84c67c1e92050374faa001fe29b457cd22f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2002 by Albert Cahalan; all rights resered.         
+ * Copyright 1998-2004 by Albert Cahalan; all rights resered.         
  * This file may be used subject to the terms and conditions of the
  * GNU Library General Public License Version 2, or any later version  
  * at your option, as published by the Free Software Foundation.
@@ -8,9 +8,6 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Library General Public License for more details.
  */                                 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
 
 #include <stdlib.h>
 #include <stdio.h>