Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <errno.h>
- int getPidd();
- int main(int argc, char* argv[])
- {
- printf("\tCommand Center\n");
- if(argc!=1)
- {
- printf("Program is working without parameters.\n");
- exit(1);
- }
- int target_pid;
- int flag=1;
- while(flag)
- {
- target_pid=getPidd();
- switch(kill(target_pid,SIGRTMIN+6))
- {
- case 0:
- printf("Signal send succesfully!\n");
- break;
- default:
- switch(errno)
- {
- case EINVAL:
- printf("The value of the sig argument is an invalid or unsupported signal number\n");
- break;
- case EPERM:
- printf("The process does not have permission to send the signal to any receiving process\n");
- break;
- case ESRCH:
- printf("No process or process group can be found corresponding to that specified by pid\n");
- break;
- }
- break;
- }
- printf("Send signal once again? (y/n): ");
- char c[1];
- scanf("%1c",c);
- switch(c[0])
- {
- case 'y':
- continue;
- break;
- case 'n':
- //exit(0);
- flag=0;
- break;
- }
- }
- return 0;
- }
- //komunikaty do kill -> errno wziete z: http://linux.die.net/man/3/kill
- int getPidd()
- {
- char target_pid[6];
- char *endint;
- int pid;
- while(1)
- {
- printf("Provide a PID:\n");
- scanf("%6s",target_pid);
- pid=strtol(target_pid,&endint,10);
- if(*endint || pid<2 || pid==getpid())
- {
- printf("Incorrect PID!\n");
- continue;
- }
- else
- {
- printf("PID: %d\n",pid);
- break;
- }
- }
- return pid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement