Check if any running binary is 32 or 64 bit

2019-07-27 04:51发布

问题:

It is possible to check if an app bundle's binary process is running in 32 or 64 bit mode, as answered in this question, but I can verify that it only works with GUI processes.

However, I need to also check processes that don't have a GUI and is not part of a bundle.

So, programmatically, without calling system functions or other executables, how can I test if any process is running in 32 or 64 bit mode, given the process pid?

回答1:

Ok, so I finally found the answer was already on SO here, for Carbon. In order to use that code now, this include is required:

#include <sys/sysctl.h>

Also, it appears that the member to the process structure has changed from

proc->kp_proc.p_flags 

to this:

proc->kp_proc.p_flag