手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2012-05-25] 来源:Linux社区  作者:wyz365889 [字体:大 中 小]

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. }  
linux
相关资讯       Linux编程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款