I like understand a execute file is 64 bit or no. I want to understand a run process in Linux is 64 bit or 32 bit with c++. I do not want to use "file" command. for example: File -L bash
Asked
Active
Viewed 273 times
-2
-
The answer is a bit unclear. You want to detect whether a file in the filesystem is a 32/64 executable? Or detect whether your own process will be 32/64? – David Rodríguez - dribeas Sep 16 '13 at 04:30
-
1detect whether own process will be 32/64 – user2760718 Sep 16 '13 at 04:32
-
possible duplicate of [Detecting 64bit compile in C](http://stackoverflow.com/questions/5272825/detecting-64bit-compile-in-c) – devnull Sep 16 '13 at 04:39
-
Also check [this](http://stackoverflow.com/questions/1505582/determining-32-vs-64-bit-in-c) – devnull Sep 16 '13 at 04:39
-
NO i need detect other process is OS.Sorry I was wrong. – user2760718 Sep 16 '13 at 04:41
3 Answers
5
You need to parse the elf header. You can write your own parser, or use a dedicated library such as this one: http://elfio.sourceforge.net/

stdcall
- 27,613
- 18
- 81
- 125
2
you should use elfio lib. this is a link for that: (http://elfio.sourceforge.net)

hamed
- 113
- 6
-
Rather than checking the binary, you can at compile time determine the result by using preprocessor macros expanded by the compiler. See the linked questions marked as duplicate. – David Rodríguez - dribeas Sep 16 '13 at 13:25