home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / ksh_util / ps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-25  |  1.6 KB  |  86 lines

  1. #include <mintbind.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #ifdef __GNUC__
  7. /* minimal stuff */
  8.  
  9. #include <minimal.h>
  10. #include <stdarg.h>
  11.  
  12. int printf(const char *fmt,...)
  13. {
  14.     va_list args;
  15.     char buf[128];
  16.     va_start(args,fmt);
  17.     vsprintf(buf,fmt,args);
  18.     Cconws(buf);
  19.     return 0;
  20. }
  21.  
  22. #undef putchar
  23. #define putchar(c) Cconout(c)
  24. #endif
  25.  
  26. struct states {
  27.     int        attribute;
  28.     char    *desc;
  29. } proc_state[] =  {
  30.     0x00,    "Currently Running",
  31.     0x01,    "Ready to Run",
  32.     0x20,    "Waiting for an event",
  33.     0x21,    "Waiting for I/O",
  34.     0x22,    "Zombie",
  35.     0x02,    "TSR",
  36.     0x24,    "Stopped",
  37.     0,        ""
  38. };
  39.  
  40. char *stateOf( int attr )
  41. {
  42.     struct states *st = proc_state;
  43.  
  44.     do
  45.     {
  46.         if ( st->attribute == attr )
  47.             return st->desc;
  48.     } while( (++st)->desc );
  49.     return "Invalid attributes";
  50. }
  51.  
  52. int main( int argc, char **argv, char **envp )
  53. {
  54.     struct _dta dta, *olddta;
  55.     
  56.     olddta = (struct _dta *)Fgetdta();
  57.  
  58.     (void)Pdomain(1);
  59.     Fsetdta( &dta );
  60.  
  61.     printf(" %3s %8s %7s %-20.20s %-13.13s\n\r\n\r",
  62.         "PID", "Time", "Size", "State", "Process Name" );
  63.  
  64.     if ( ! Fsfirst( "x:/*.*", 0 ) )
  65.         do
  66.         {
  67.             int i;
  68.             char tmp[9];
  69.             unsigned t;
  70.  
  71.             t = dta.dta_time;
  72.  
  73.             i = strcspn( dta.dta_name, "." );
  74.             memcpy( tmp, dta.dta_name, i );
  75.             tmp[i] = '\0';
  76.             
  77.             printf( " %3d %02d:%02d:%02d %7ld %-20.20s %-13.13s\n\r",
  78.                 atoi( &dta.dta_name[i+1] ),
  79.                 (t >> 11) & 31, (t >> 5) & 63, (t & 31) << 1,
  80.                 dta.dta_size, stateOf(dta.dta_attribute), tmp );
  81.         } while ( ! Fsnext() );
  82.  
  83.     Fsetdta( &olddta );
  84.     return 0;        /* keep the compiler happy */
  85. }
  86.