zoukankan      html  css  js  c++  java
  • c++ 遍历当前程序的线程

    #include <iostream>
    #include <Windows.h>
    #include <Psapi.h>
    #include <TlHelp32.h>
    
    
      HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
    
      if (hSnap != INVALID_HANDLE_VALUE)
      {
        THREADENTRY32 te;
        te.dwSize = sizeof(THREADENTRY32);
        if ( Thread32First(hSnap, &te) )
        {
          do
          {
            if (te.th32OwnerProcessID == GetCurrentProcessId())
            {
              printf("pid: %d, tid: %d, 优先级: %d
    ", te.th32OwnerProcessID, te.th32ThreadID, te.tpBasePri);
    
              // 关闭线程 
              HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, false, te.th32ThreadID);
              TerminateThread(hThread, 1);
              CloseHandle(hThread);
            }
          } while (Thread32Next(hSnap, &te));
        }
      }
    
      CloseHandle(hSnap);
    
  • 相关阅读:
    thinkphp 前台输出
    php的四种定界符
    面试总结
    Git分布式版本控制工具
    Apache Dubbo
    Mybatis03
    Mybatis02
    Mybaitis01
    linux下如何安装webbench
    SpringUtil
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13739017.html
Copyright © 2011-2022 走看看