home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / idle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.6 KB  |  82 lines

  1. /* idle.c (emx+gcc) */
  2.  
  3. #define INCL_DOSPROCESS
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <process.h>
  8. #include <os2.h>
  9.  
  10. static void dump_tib (void)
  11. {
  12.   PTIB ptib;
  13.   PPIB ppib;
  14.  
  15.   if (DosGetInfoBlocks (&ptib, &ppib) == 0)
  16.     {
  17.       printf ("Stack base: %.8lx\n", (long)ptib->tib_pstack);
  18.       printf ("Stack limit: %.8lx\n", (long)ptib->tib_pstacklimit);
  19.       printf ("Priority: %.8lx\n", (long)ptib->tib_ptib2->tib2_ulpri);
  20.     }
  21. }
  22.  
  23.  
  24. int main (int argc, char *argv[])
  25. {
  26.   ULONG rc;
  27.   int i, arg0, len, verbose;
  28.   char *p;
  29.  
  30.   arg0 = 1; verbose = 0;
  31.   if (arg0 < argc && strcmp (argv[arg0], "-v") == 0)
  32.     {
  33.       verbose = 1;
  34.       ++arg0;
  35.     }
  36.   if (arg0 < argc && strcmp (argv[arg0], "-t") == 0)
  37.     {
  38.       verbose = 2;
  39.       ++arg0;
  40.     }
  41.   if (arg0 >= argc)
  42.     {
  43.       printf ("Usage: idle <command>\n");
  44.       return (1);
  45.     }
  46.   if (verbose >= 2)
  47.     dump_tib ();
  48.   rc = DosSetPriority (PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0);
  49.   if (verbose >= 2)
  50.     dump_tib ();
  51.   if (rc != 0)
  52.     {
  53.       fprintf (stderr, "DosSetPriority failed, rc=%lu\n", rc);
  54.       return (2);
  55.     }
  56.   len = 1;
  57.   for (i = arg0; i < argc; ++i)
  58.     len += strlen (argv[i]) + 1;
  59.   p = malloc (len);
  60.   if (p == NULL)
  61.     {
  62.       perror ("malloc");
  63.       return (2);
  64.     }
  65.   *p = 0;
  66.   for (i = arg0; i < argc; ++i)
  67.     {
  68.       if (i > arg0)
  69.         strcat (p, " ");
  70.       strcat (p, argv[i]);
  71.     }
  72.   i = system (p);
  73.   if (i < 0)
  74.     {
  75.       perror ("system");
  76.       return (2);
  77.     }
  78.   else if (verbose >= 1)
  79.     printf ("Return code = %d\n", i);
  80.   return (i);
  81. }
  82.