Advertisement
Geralt1001

Untitled

Feb 13th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <signal.h>
  5.  
  6. int getPidd();
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10.     printf("\tCommand Center\n");
  11.    
  12.     if(argc!=1)
  13.     {
  14.         printf("Program is working without parameters.\n");
  15.         exit(1);
  16.     }
  17.     int target_pid;
  18.    
  19.     target_pid=getPidd();
  20.    
  21.     switch(kill(target_pid,SIGRTMIN+6))
  22.     {
  23.         case 0:
  24.             printf("Signal send succesfully!\n");
  25.             break;
  26.         default:
  27.             switch(errno)
  28.             {
  29.                 case EINVAL:
  30.                     printf("The value of the sig argument is an invalid or unsupported signal number\n");
  31.                     break;
  32.                 case EPERM:
  33.                     printf("The process does not have permission to send the signal to any receiving process\n");
  34.                     break;
  35.                 case ERSCH:
  36.                     printf("No process or process group can be found corresponding to that specified by pid\n");
  37.                     break;
  38.             }
  39.             break;
  40.     }
  41. }
  42.  
  43. int getPidd()
  44. {
  45.     char target_pid[6];
  46.     char *endint;
  47.     int pid;
  48.     while(1)
  49.     {
  50.         printf("Provide a PID:\n");
  51.         scanf("%6s",target_pid);
  52.  
  53.         pid=strtol(target_pid,&endint,10);
  54.         if(*endint || pid<=2 || pid==getpid())
  55.         {
  56.             printf("Incorrect PID!\n");
  57.             continue;
  58.         }
  59.         else
  60.         {
  61.             printf("PID: %d\n",pid);
  62.             break;
  63.         }
  64.     }
  65.     return pid;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement