home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / condor40.zip / CONDOR / src / util_lib / proc.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  5KB  |  160 lines

  1. /* 
  2. ** Copyright 1986, 1987, 1988, 1989 University of Wisconsin
  3. ** 
  4. ** Permission to use, copy, modify, and distribute this software and its
  5. ** documentation for any purpose and without fee is hereby granted,
  6. ** provided that the above copyright notice appear in all copies and that
  7. ** both that copyright notice and this permission notice appear in
  8. ** supporting documentation, and that the name of the University of
  9. ** Wisconsin not be used in advertising or publicity pertaining to
  10. ** distribution of the software without specific, written prior
  11. ** permission.  The University of Wisconsin makes no representations about
  12. ** the suitability of this software for any purpose.  It is provided "as
  13. ** is" without express or implied warranty.
  14. ** 
  15. ** THE UNIVERSITY OF WISCONSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. ** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. ** FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN  BE LIABLE FOR
  18. ** ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. ** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  21. ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ** 
  23. ** Authors:  Allan Bricker and Michael J. Litzkow,
  24. **              University of Wisconsin, Computer Sciences Dept.
  25. ** 
  26. */ 
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <sys/time.h>
  31. #include <sys/resource.h>
  32. #include "proc.h"
  33. #include "clib.h"
  34.  
  35. int        DontDisplayTime;
  36.  
  37. display_proc_short( proc )
  38. PROC    *proc;
  39. {
  40.     char        activity;
  41.     struct tm    *tm, *localtime();
  42.     char        *format_time();
  43.  
  44.     switch( proc->status ) {
  45.         case UNEXPANDED:
  46.             activity = 'U';
  47.             break;
  48.         case IDLE:
  49.             activity = 'I';
  50.             break;
  51.         case RUNNING:
  52.             activity = 'R';
  53.             break;
  54.         case COMPLETED:
  55.             activity = 'C';
  56.             break;
  57.         case REMOVED:
  58.             activity = 'X';
  59.             break;
  60.         default:
  61.             activity = ' ';
  62.     }
  63.  
  64.     tm = localtime( (time_t *)&proc->q_date );
  65.  
  66.     if( strlen(proc->cmd) > 22 )
  67.         proc->cmd[22] = '\0';
  68.  
  69.     if( strlen(proc->owner) > 14 )
  70.         proc->owner[14]= '\0';
  71.  
  72.  
  73.     printf( "%4d.%-3d %-14s %2d/%-2d %02d:%02d %s %-2c %-3d %-22s\n",
  74.         proc->id.cluster, proc->id.proc, proc->owner,
  75.         tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min,
  76.         /* format_time(proc->cpu_time), */ 
  77.         format_time((float)proc->remote_usage.ru_utime.tv_sec),
  78.         activity, proc->prio, proc->cmd );
  79.             
  80. }
  81.  
  82. #define SECOND    1
  83. #define MINUTE    (60 * SECOND)
  84. #define HOUR    (60 * MINUTE)
  85. #define DAY        (24 * HOUR)
  86.  
  87. char    *
  88. format_time( fp_secs )
  89. float        fp_secs;
  90. {
  91.     int        days;
  92.     int        hours;
  93.     int        min;
  94.     int        secs;
  95.     int        tot_secs = fp_secs;
  96.     static char    answer[25];
  97.  
  98.     days = tot_secs / DAY;
  99.     tot_secs %= DAY;
  100.     hours = tot_secs / HOUR;
  101.     tot_secs %= HOUR;
  102.     min = tot_secs / MINUTE;
  103.     secs = tot_secs % MINUTE;
  104.  
  105.     (void)sprintf( answer, "%3d %02d:%02d:%02d", days, hours, min, secs );
  106.     return answer;
  107. }
  108.  
  109. char *Notifications[] = {
  110.     "Never", "Always", "Complete", "Error"
  111. };
  112.  
  113. display_proc_long( proc )
  114. PROC    *proc;
  115. {
  116.     (void)putchar( '\n' );
  117.     printf( "Id: %d.%d\n", proc->id.cluster, proc->id.proc );
  118.     printf( "Owner: %s\n", proc->owner );
  119.     printf( "Queue Date: %s", ctime( (time_t *)&proc->q_date ) );
  120.     printf( "Status: %d\n", proc->status );
  121.     printf( "Priority: %d\n", proc->prio );
  122.     printf( "Notification: %s\n", Notifications[proc->notification]);
  123.     printf( "Cmd: %s\n", proc->cmd );
  124.     printf( "Args: %s\n", proc->args );
  125.     printf( "Env: %s\n", proc->env );
  126.     printf( "In: %s\n", proc->in );
  127.     printf( "Out: %s\n", proc->out );
  128.     printf( "Err: %s\n", proc->err );
  129.     printf( "RootDir: %s\n", proc->rootdir );
  130.     printf( "Initial Working Directory: %s\n", proc->iwd );
  131.     printf( "Requirements: %s\n", proc->requirements );
  132.     printf( "Preferences: %s\n", proc->preferences );
  133.  
  134.         /* If we're called by "condor", then all cpu times are known to be
  135.            zero, so don't display them. */
  136.     if( DontDisplayTime ) {
  137.         return;
  138.     }
  139.  
  140.     /*
  141.     **    Should print rusage...
  142.     printf( "Cpu Time: %f\n", proc->cpu_time );
  143.     */
  144.     printf( "Local User Time:      %s\n",
  145.         format_time((float)proc->local_usage.ru_utime.tv_sec) );
  146.     printf( "Local System Time:    %s\n",
  147.         format_time((float)proc->local_usage.ru_stime.tv_sec) );
  148.     printf( "Total Local Time:     %s\n",
  149.         format_time((float)proc->local_usage.ru_utime.tv_sec +
  150.                             proc->local_usage.ru_stime.tv_sec) );
  151.  
  152.     printf( "Remote User Time:     %s\n",
  153.         format_time((float)proc->remote_usage.ru_utime.tv_sec) );
  154.     printf( "Remote System Time:   %s\n",
  155.         format_time((float)proc->remote_usage.ru_stime.tv_sec) );
  156.     printf( "Total Remote Time:    %s\n",
  157.         format_time((float)proc->remote_usage.ru_utime.tv_sec +
  158.                             proc->remote_usage.ru_stime.tv_sec) );
  159. }
  160.