C++获取当前进程的进程号方法

来源: http://hi.baidu.com/dnboy/blog/item/064ef4005944d482e850cd51.html

其实我们系统中有现成的函数可以获取到进程号,如下:

#ifdef _WIN32

#include <process.h>

#else

#include <unistd.h>

#endif

int main()

{

    int iPid = (int)getpid();

    std::cout<<"The process id is: "<<iPid<<std::endl;

    return 0;

}

有些定义为pid_t getpid(),其实pid_t的类型就是int类型,定义如下:typedef int pid_t;

原文地址:https://www.cnblogs.com/dabaopku/p/1772407.html