系统相关
首页 > 系统相关> > 获取进程/线程ID及常用函数

获取进程/线程ID及常用函数

作者:互联网

获取进程/线程ID

#ifdef WIN32
#include "windows.h"
#else
#include "unistd.h"
#endif

#ifdef WIN32
	printf("pid is %d \n", GetCurrentProcessId());
	printf("tid is %d \n", GetCurrentThreadId());

#else
	printf("pid is %d \n", getpid());
	printf("tid is %d \n", gettid());
#endif

线程操作:

ExitThread(3);                                                              //正常结束一个线程函数
TerminateThread(handle);                                       //强制结束一个线程函数,不推荐使用的方式
GetExitCodeThread(handle,&dw);                          //获取线程结束的退出码

SuspendThread(handle);                                         //挂起\暂停\休眠一个线程
ResumeThread(handle);                                          //唤醒一个线程

GetThreadPriority(handle);                                       //获得线程的优先级
SetThreadPriority(handle);                                       //设置线程的优先级

ClosseHandle(handle);                                            //释放线程句柄  

//伪代码
hThread = ::CreateThread(NULL,0, ThreadProcIdle, NULL, CREATE_SUSPENDED, &dwThreadIdIdle);  
::SetThreadPriority(hThread,THREAD_PRIORITY_IDLE);  
::ResumeThread(hThread);  

 

标签:handle,函数,pid,线程,printf,NULL,ID,hThread
来源: https://blog.csdn.net/u014037733/article/details/110311394