I following Michael's reply to see what executable formats my Ubuntu can recognize to execute
$ ls -l /proc/sys/fs/binfmt_misc/
total 0
-rw-r--r-- 1 root root 0 Apr 19 16:11 cli
-rw-r--r-- 1 root root 0 Apr 19 16:11 jar
-rw-r--r-- 1 root root 0 Apr 19 16:11 python2.7
-rw-r--r-- 1 root root 0 Apr 19 16:11 python3.5
--w------- 1 root root 0 Apr 19 16:11 register
-rw-r--r-- 1 root root 0 Apr 19 16:11 status
I have never intentionally changed anything there, and the files were created by default or when I installed some other programs.
$ cat /proc/sys/fs/binfmt_misc/cli
enabled
interpreter /usr/lib/binfmt-support/run-detectors
flags:
offset 0
magic 4d5a
What kind of executable format is this? I googled "magic 4d5a" and found https://en.wikipedia.org/wiki/DOS_MZ_executable, but I am not sure how the file was created there since it is not a native executable format to Linux. Did installation of wine
add it?
$ cat /proc/sys/fs/binfmt_misc/jar
enabled
interpreter /usr/lib/jvm/java-9-oracle/lib/jexec
flags:
offset 0
magic 504b0304
Is the above for JVM bytecode format?
$ cat /proc/sys/fs/binfmt_misc/python3.5
enabled
interpreter /usr/bin/python3.5
flags:
offset 0
magic 160d0d0a
Is the above for Python bytecode or Python?
$ cat /proc/sys/fs/binfmt_misc/status
enabled
$ cat /proc/sys/fs/binfmt_misc/register
cat: /proc/sys/fs/binfmt_misc/register: Permission denied
What is /proc/sys/fs/binfmt_misc/register
used for? Does it also allow some executable format?
Does ELF format need a file under /proc/sys/fs/binfmt_misc/
?
Thanks.
execve()
? Can the first argument toexecve()
be either a file containing a magic word set up by binfmt_misc, or a file containing a shebang? https://unix.stackexchange.com/questions/439376/how-is-a-bash-script-executed-via-its-filename-as-command-name-with-and-without#comment795018_439390 – Tim Apr 23 '18 at 22:14execve
manpage: the first argument can point to either a binary executable, or a script starting with a shebang. What constitutes a binary executable is determined by the kernel: in Linux, binaries are supported by one of thebinfmt_
modules, which includea.out
, ELF,em86
(on Alpha), flat files, “misc” (as inbinfmt_misc
), and scripts with a shebang. (So the Linux implementation treats scripts in the same way as binaries.) – Stephen Kitt Apr 24 '18 at 11:16a.out
? Do you mean ELF? Whengcc my.c
, it generatesa.out
, which has ELF format. (2) What does " flat files" mean? I heard that flat files are text files in database like scenario (https://en.wikipedia.org/wiki/Flat_file_database), but not sure that is what you meant (3) What does “misc” as inbinfmt_misc
mean? (4) What is the source/reference for the sentence? – Tim Apr 24 '18 at 12:29a.out
means a.out, the old executable format. (And yes, many C compilers usea.out
as their default target name, independently of the format...) “Flat files” refers to the uClinux binary format. – Stephen Kitt Apr 24 '18 at 12:38binfmt_
modules". What otherbinfmt_
modules besidesbinfmt_misc
?lsmod | grep binfmt_
andlocate binfmt_
only showbinfmt_misc
. – Tim Apr 24 '18 at 12:39binfmt
modules in most systems; for example, current Debian kernels build ELF and script support into the kernel,binfmt_misc
as a module, and nothing else. – Stephen Kitt Apr 24 '18 at 12:41binfmt_misc
provides support for miscellaneous binary formats, that’s why it’s named that way. – Stephen Kitt Apr 24 '18 at 12:42