1

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.

Community
  • 1
  • 1
Dave
  • 7,283
  • 12
  • 55
  • 101

2 Answers2

2

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 (i.e. 64-bit) mode. In the above example, flags=4004, so the process listed is 64-bit.

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
1

Use file:

file -L /proc/[PID]/exe
Yakubs
  • 161
  • 2
  • 11