golang1.8使用cgo获取进程是否假死

前端之家收集整理的这篇文章主要介绍了golang1.8使用cgo获取进程是否假死前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. package main
  2.  
  3. import (
  4. "flag"
  5. )
  6.  
  7. /*
  8. #include <stdio.h>
  9. #include <windows.h>
  10. #include <Winuser.h>
  11. typedef struct EnumFunArg
  12. {
  13. HWND hWND;
  14. DWORD dwProcessId;
  15. }EnumFunArg,*LPEnumFunArg;
  16.  
  17. BOOL CALLBACK lpEnumFunc(HWND hwnd,LPARAM lParam)
  18. {
  19. EnumFunArg *pArg = (LPEnumFunArg)lParam;
  20. DWORD processId;
  21. GetWindowThreadProcessId(hwnd,&processId);
  22. if( processId == pArg->dwProcessId)
  23. {
  24. pArg->hWND = hwnd;
  25. return FALSE;
  26. }
  27. return TRUE;
  28. }
  29.  
  30. int ReturnWnd(DWORD processID)
  31. {
  32. BOOL re = FALSE;
  33. EnumFunArg wi;
  34. wi.dwProcessId = processID;
  35. wi.hWND = NULL;
  36. EnumWindows(lpEnumFunc,(LPARAM)&wi);
  37. if(wi.hWND)
  38. {
  39. if (IsHungAppWindow(wi.hWND))
  40. {
  41. return 1;
  42. }
  43. }
  44. else
  45. {
  46. return -1;
  47. }
  48. return 0;
  49. }
  50. */
  51. import "C"
  52.  
  53. func main() {
  54. pid := flag.Int("p",0,"-p 1001")
  55. flag.Parse()
  56. h := C.ReturnWnd(C.DWORD(*pid))
  57. switch h {
  58. case 0:
  59. println("程序有响应")
  60. case 1:
  61. println("程序无响应")
  62. case -1:
  63. println("无法获取窗口")
  64. }
  65. }

猜你在找的Go相关文章