简体   繁体   中英

Check if a running process is 32 or 64 bit

How can I determine if a specified process is 32 or 64 bit on Windows, Mac and Linux.

On Linux and Mac I have a pid of the process. I am thinking that if the system itself is 64 bit then the apps should be 64 bit, same with 32 bit. But I heard that 64 bit Linux and Mac can also run 32 bit applications. What can I do to be sure?

On Windows I have a Handle to the process. Currently I am using IsWow64Process. Is this correct? (Edit: yes it is correct but needs to be used with GetNativeSystemInfo to see if the OS is 64 bit).

EDIT: For Mac see this question.

使用文件:

file -L /proc/[PID]/exe

On OS X, ps 's flags value includes a bit that indicates 64-bit mode:

$ ps -oflags= [PID]
        4004

From the ps man page:

 flags     The flags associated with the process as in the include file
           <sys/proc.h>:

           P_ADVLOCK           0x00001      Process may hold a POSIX
                                            advisory lock
           P_CONTROLT          0x00002      Has a controlling terminal
           P_LP64              0x00004      Process is LP64
           P_NOCLDSTOP         0x00008      No SIGCHLD when children stop
           [etc...]

...so if the flags value's last digit is 4, 5, 6, 7, c, d, e, or f, it's running in LP64 (ie 64-bit) mode. In the above example, flags=4004, so the process listed is 64-bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM