#include #include #include int main(int argc, char** argv){ char buff[1028]; char p_name[1028]; int* PIDs = malloc(100*sizeof(int)); if(argc<2){ printf("Usage :\nfirst parameter is the name of the program to be killed. it'll then ask you which one that matches do you want to kill\n"); } else if(argv[1][0]=='-'){ switch(argv[1][1]){ case 'h': printf("Usage :\nfirst parameter is the name of the program to be killed. it'll then ask you which one that matches do you want to kill\n"); break; case 'v': printf("v0.0\n"); default: printf("Unknown option : -%c\n",argv[1][1]); } } else{ char* cmd= malloc(18+strlen(argv[1])); sprintf(cmd,"ps aux | grep %s",argv[1]); FILE* c = popen(cmd,"r"); int i=0; printf("which one do you want to kill ?\n"); while(fgets(buff,1028,c)!=NULL){ sscanf(buff,"%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",p_name,PIDs+i,p_name,p_name,p_name,p_name,p_name,p_name,p_name,p_name,p_name); printf("%d : %s\n",i,p_name); i++; } scanf("%d",&i); sprintf(cmd,"/usr/bin/kill -SIGKILL %d",PIDs[i]); system(cmd); } }