Is there a way to check if process is 64 bit or 32 bit?

前端 未结 3 1872
梦谈多话
梦谈多话 2020-12-09 20:34

I am trying to find process type (32 bit/ 64bit) from process pid?

I get the process information and process list from using GetBSDProcessList method described here.

3条回答
  •  Happy的楠姐
    2020-12-09 21:16

    Okay so I did a lot of research and figured out a better solution. Although the sysctl approach works, the documentation states it should be avoided. The method below uses libproc.h's proc_pidinfo function and works similarly to sysctl. This is obviously for Apple's platforms.

    bool Is64Bit (int pid)
    {
        proc_bsdshortinfo info;
        if (proc_pidinfo (pid, PROC_PIDT_SHORTBSDINFO,
            0, &info, PROC_PIDT_SHORTBSDINFO_SIZE))
            return info.pbsi_flags & PROC_FLAG_LP64;
    
        return false;
    }
    

提交回复
热议问题