Linux之根据某进程名杀死进程


Linux之根据某进程名杀死进程:

  1. #include <iostream>   
  2.   
  3. #include <string>   
  4. #include <stdio.h>   
  5. #include <stdlib.h>   
  6. #include <fcntl.h>   
  7. #include <string.h>   
  8. using namespace std;  
  9. int main()  
  10. {  
  11.     /*int fd; 
  12.     fd = open("/sddisk/tmpfile",O_RDWR|O_CREAT); 
  13.  
  14.     if(fd==-1) 
  15.     { 
  16.         printf("Read sdcard failure!"); 
  17.     } 
  18.     else 
  19.     { 
  20.         printf("Read sdcard success!"); 
  21.     } 
  22.  
  23.     char ch[10]; 
  24.     char cc ; 
  25.     char szBuff[256]; 
  26.     short int i = 0; 
  27.     short int j = 0; 
  28.  
  29.     FILE *fp; 
  30.     system("ls /dev/>/tmp/a.txt"); 
  31.     fp = fopen("/tmp/a.txt", "r"); 
  32.     while( !feof( fp )) 
  33.         { 
  34.         memset( szBuff, 0, 256 ); 
  35.         fgets( szBuff, 256, fp ); 
  36.  
  37.         if(NULL != strstr(szBuff,"mmcblk")){ 
  38.             printf("Read sdcard success!\n"); 
  39.             break; 
  40.          }         
  41.          } 
  42.     fclose(fp); 
  43.     system("rm /tmp/a.txt");*/  
  44.   
  45.         char ch[10];  
  46.         char cc ;  
  47.         char szBuff[256];  
  48.         short int i = 0;  
  49.         short int j = 0;  
  50.           
  51.         FILE *fp;  
  52.         system("ps -www | grep output_file* >/tmp/a.txt");  
  53.         fp = fopen("/tmp/a.txt""r");  
  54.         while( !feof( fp ))  
  55.         {  
  56.                 memset( szBuff, 0, 256 );  
  57.                 fgets( szBuff, 256, fp );  
  58.                 char buf[10];  
  59.                 memset( buf, 0, 10 );  
  60.                 sscanf(szBuff,"%[^root]", buf);  
  61.                 printf("wyz------------sssxx:%s\n",buf);  
  62.                 string ss(buf);  
  63.                 ss="kill -9"+ss;  
  64.                 system(ss.c_str());  
  65.                 printf("wyz------------ss:%s\n",szBuff);  
  66.                 break;  
  67.         }  
  68.         fclose(fp);  
  69.         system("rm /tmp/a.txt");  
  70.     return 1;  
  71. }  

相关内容