歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux之根據某進程名殺死進程

Linux之根據某進程名殺死進程

日期:2017/3/1 10:22:11   编辑:Linux編程

Linux之根據某進程名殺死進程:

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