←back to thread

185 points thunderbong | 2 comments | | HN request time: 0s | source
Show context
Imustaskforhelp ◴[] No.43647155[source]
Read your article, it's really nice. I really feel much less demystified by this.

But can you / somebody please explain what this means

According to the official Kernel Admin Guide:

This Kernel feature allows you to invoke almost (for restrictions see below) every program by simply typing its name in the shell. This includes for example compiled Java(TM), Python or Emacs programs. To achieve this you must tell binfmt_misc which interpreter has to be invoked with which binary. Binfmt_misc recognises the binary-type by matching some bytes at the beginning of the file with a magic byte sequence (masking out specified bits) you have supplied. Binfmt_misc can also recognise a filename extension aka .com or .exe.

It’s another way to tell the Kernel what interpreter to run when invoking a program that’s not native (ELF). For scripts (text files) we mostly use a shebang, but for byte-coded binaries, such as Java’s JAR or Mono EXE files, it’s the way to go!

Like, can you give me an example by what you mean. What are its use cases, if any. I read it many times and always with some sort of enthusiasm because of this sentence ending in exclamation point making me feel like it's huge yet I just can't understand it's significance.

Does it mean we can have .jar files which can then run shebang like, so we don't need #! , can this also be used for main.go or every other language which has some issues with #! ,

I see there being some interpreter for golang, rust etc. which just compiles it but it was just too complex. I am just imagining something like a simple go file which is valid golang but can be run by linux simply by ./ And it autocompiles it...

replies(4): >>43647278 #>>43647280 #>>43649406 #>>43649840 #
1. ckatri ◴[] No.43647278[source]
The best and most common uses for this are Wine and qemu-static.

For example, the following (which I grabbed from Wikipedia) `:DOSWin:M::MZ::/usr/bin/wine:` will register `/usr/bin/wine` to run as the wrapper for any .exe that gets executed, with no extra config needed. It simply sees that you tried to run a PE file and will run it in wine.

replies(1): >>43650577 #
2. Imustaskforhelp ◴[] No.43650577[source]
okay so now you can have some command which you can run which would do somethings with procfs/what not and now you can simply run any jar or exe file as it is....

That is really nice actually!

this could theoretically be used as a scriptesto alternative but it requires some command to run , I was hoping there was a way to use something other than shebang