home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / sysutils / kill / kill.c next >
Encoding:
C/C++ Source or Header  |  1992-07-09  |  1.1 KB  |  53 lines

  1. /* kill.c */
  2.  
  3. #define INCL_DOSPROCESS
  4. #define INCL_DOSERRORS
  5.  
  6. #include <os2.h>
  7. #include <stdio.h>
  8.  
  9. int main( int argc, char **argv )
  10. {
  11.    int iScan;
  12.    ULONG ulStat;
  13.    PID pid;
  14.  
  15.    if( argc <= 1 )
  16.    {
  17.       printf("Usage:\n\tkill <pid>\n\n");
  18.       printf("where <pid> is a valid process ID as given in\nthe ");
  19.       printf("output of the OS/2 utility \"pstat/c\"\n");
  20.       fflush(stdout);
  21.       exit(0);
  22.    }
  23.    else
  24.    {
  25.       iScan = sscanf(argv[1],"%x",&pid);
  26.       if( iScan <= 0 )
  27.       {
  28.      printf("Invalid PID! Use the OS/2 command \"pstat/c\" to\n");
  29.      printf("get a list of running processes.\n");
  30.      fflush(stdout);
  31.      exit(0);
  32.       }
  33.    }
  34.       
  35.    ulStat = DosKillProcess( EXIT_PROCESS, pid );
  36.  
  37.    switch( ulStat )
  38.    {
  39.       case NO_ERROR:
  40.          printf("Process successfully killed...\n");
  41.          break;
  42.  
  43.       case ERROR_INVALID_PROCID:
  44.      printf("Invalid PID! Use the OS/2 command \"pstat/c\" to\n");
  45.      printf("get a list of running processes!\n");
  46.      break;
  47.    }
  48.  
  49.    fflush(stdout);
  50.    return 0;
  51.    
  52. }
  53.