home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 074.lha / Exec / tp.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  2KB  |  72 lines

  1. /*
  2.  *    tp.c
  3.  *
  4.  *    Usage: tp [taskname] [priority]
  5.  *
  6.  *    This program changes the priority of the specified task. If
  7.  *    priority is not specified, then the current priority of the
  8.  *    task is displayed. If the taskname is not specified, then the
  9.  *      current tasks's priority is changed (or displayed). This changes
  10.  *      task priorities, not process priorities, so it is possible to 
  11.  *      change the priorities of system tasks. Extreme care must be
  12.  *      taken when doing this as the default priority settings don't
  13.  *      leave much room in them    for change. Note that if three tasks 
  14.  *      have the same name then    then only one (and it's impossible to
  15.  *    say which one) will be changed.
  16.  *
  17.  *    Program        Date        Action
  18.  *    D. Thomas    18 Oct 1987    v1.0 Initial Coding.
  19.  *
  20.  */
  21.  
  22. #include "exec/tasks.h"
  23. #include "functions.h"
  24.  
  25. #define USAGE "[%s rev. 1.0, 18 October 1987]\nUsage: %s taskname priority\n"
  26.  
  27. extern struct ExecBase *SysBase;    /* Exec's base ptr */
  28.  
  29. main (argc, argv)
  30.  
  31. int   argc;
  32. char *argv[];
  33.  
  34. {
  35.  
  36.   register struct Task *t;        /* task pointer */
  37.   long int              priority = -999;   /* new task priority */
  38.   long int              oldpriority;
  39.   char                 *taskname = NULL;
  40.  
  41.   if (argc == 3 && 
  42.       (sscanf (argv[2], "%ld", &priority) != 1 ||
  43.        priority < -128 ||
  44.        priority > 127)) {
  45.     printf (USAGE, argv[0], argv[0]);
  46.     printf ("'%s' is not a valid task priority.\nTask priorities are decimal integers from -128 to +127\n",
  47.       argv[2]);
  48.     exit (1);
  49.   }
  50.   else if (argc == 3)
  51.     taskname = argv[1];
  52.   else if (argc == 2 && sscanf (argv[1], "%ld", &priority) != 1)
  53.     taskname = argv[1];
  54.  
  55.   if ((t = FindTask (taskname)) == 0) {
  56.     printf ("Task '%s' not found on system.\n", taskname);
  57.     exit (1);
  58.   }
  59.  
  60.   if (priority >= -128 && priority < 127) {
  61.     oldpriority = SetTaskPri (t, priority);
  62.     printf ("Task %s%spriority changed from %ld to %ld\n",
  63.       taskname, (taskname != NULL ? " " : ""), oldpriority, priority);
  64.   }
  65.   else
  66.     printf ("Task %s%spriority is %d\n", taskname,
  67.      (taskname != NULL ? " " : ""), t->tc_Node.ln_Pri);
  68.  
  69.   exit (0);
  70.  
  71. }
  72.