An old gem found

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
For so many years of using Linux and yet I'm not aware of this old gem. Well it's hard to be mastering Linux after all, isn't it ?
Lets see if there are other Linux experts around whom can observe what is the interesting part based on the behaviour of the commands listed below.
Code:
$ cat test.py
print("Hello World")
$ ls -al test.py
-rwxrw-r-- 1 ubuntu ubuntu 21 Sep  4 01:56 test.py
$ ./test.py
Hello World
$ cat test.java
public class test {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}
$ ls -al test.java
-rwxrw-r-- 1 ubuntu ubuntu 104 Sep  4 02:19 test.java
$ ./test.java
Hello World
$

Hint: I was researching on Rosetta 2 on Linux ARM64 VM when I trip upon this gem and found it is a system-wide solution that it not limited to running x86 binaries on ARM64 architecture, but it is applicable to other stuffs like Python and Java and many more.

:)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
8fo6vci.png

Well that is why when it works for me, it must be a gem, right? :)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
Hmmm no one gonna ask ChatGPT for an answer? This technology should have been around since 1997
:)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
Quite positive these cannot run in early-mid 90s, my env was RH/Slack and python was not even installed
Python is around since 1991. It is not designed to run Python anyway. What I provided is just example of how it can be used.
:)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
Here is another sample driving ansible playbook
Code:
$ ls -al sample.playbook
-rwxrw-r-- 1 ubuntu ubuntu 129 Sep  4 18:40 sample.playbook
$ cat sample.playbook
---
- name: Testing Server
  hosts: localhost
  remote_user: ubuntu

  tasks:
  - name: Ping localhost
    ansible.builtin.ping:
$ ./sample.playbook
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does
not match 'all'

PLAY [Testing Server] *****************************************************************************************

TASK [Gathering Facts] ****************************************************************************************
ok: [localhost]

TASK [Ping localhost] *****************************************************************************************
ok: [localhost]

PLAY RECAP ****************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

$
 

Trader11

Banned
Joined
Oct 14, 2018
Messages
15,698
Reaction score
5,233
Python is around since 1991. It is not designed to run Python anyway. What I provided is just example of how it can be used.
:)
Why you run python like an exe ah? Did you convert python and Java code into an executable?
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299

Trader11

Banned
Joined
Oct 14, 2018
Messages
15,698
Reaction score
5,233
Here is another sample driving ansible playbook
Code:
$ ls -al sample.playbook
-rwxrw-r-- 1 ubuntu ubuntu 129 Sep  4 18:40 sample.playbook
$ cat sample.playbook
---
- name: Testing Server
  hosts: localhost
  remote_user: ubuntu

  tasks:
  - name: Ping localhost
    ansible.builtin.ping:
$ ./sample.playbook
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does
not match 'all'

PLAY [Testing Server] *****************************************************************************************

TASK [Gathering Facts] ****************************************************************************************
ok: [localhost]

TASK [Ping localhost] *****************************************************************************************
ok: [localhost]

PLAY RECAP ****************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

$
How come each program can just run with the correct program? Does the tool detects the file extension and run the tool accordingly?
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
How come each program can just run with the correct program? Does the tool detects the file extension and run the tool accordingly?
More than just the above technique. File extension is possible, but you can also activate it via File Magic Numbers. Know what are File Magic Numbers ? This hint should be able to get you somewhere by searching or probably asking ChatGPT.

:)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
I am not disputing when Python was invented. I am stating when Python was introduced into distros base
Sure, doesn't matter. There was a time shell script is everything. It is still everywhere right now. The same for Perl and I still love Perl till now.

Learning software development is never really about which programming languages, it is always about problem solving in a particular ecosystem. The ecosystem is where one hone his/her craft.

For me personally, I spend my time in the Unix world. IMHO it's much more vibrant than the M$ world.
I started off with Arch, RH nor Slack nor Debian works for me in my laptop back in 2000 due to the soft modem (at least based on my skill set back then).

:)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
In your wiki link, it states the then kernel can handle Java directly.

https://www.kernel.org/doc/html/latest/admin-guide/java.html
But I need to install JDK first? I also need to compile CONFIG_BINFMT_MISC in the kernel?

Are these two steps still needed for the modern kernel? No more compiling or even xf86config for me, I personally fried 2 monitors with the latter during the mid 90s.

Thanks for your PM and help!

No kernel handle Java today. Compiled Java codes can only be run on a JVM, not unless you have an JVM OS.

All binfmt_misc does is offload the execution to an interpreter. the java wrapper found in the documentation is just handing over the execution of the class files with the magic number https://dzone.com/articles/the-magic-word-in-java-cafebabe to the java wrapper that will invoke the JVM via java.

You don’t need the JDK, JRE should be sufficient. You only need the JDK if you are going to develop.

If you are running java source code like the way I demonstrated earlier, then you may require the JDK. No java source code runs on its own, it must always be compiled AOT or JIT before execution.

CONFIG_BINFMT_MISC=y|m feature should be enabled for the kernel build.

:)
 
Last edited:

xcodes

Great Supremacy Member
Joined
Dec 15, 2013
Messages
63,778
Reaction score
29,064
No kernel handle Java today. Compiled Java codes can only be run on a JVM, not unless you have an JVM OS.

All binfmt_misc does is offload the execution to an interpreter. the java wrapper found in the documentation is just handing over the execution of the class files with the magic number https://dzone.com/articles/the-magic-word-in-java-cafebabe to the java wrapper that will invoke the JVM via java.

You don’t need the JDK, JRE should be sufficient. You only need the JDK if you are going to develop.

If you are running java source code like the way I demonstrated earlier, then you may require the JDK. No java source code runs on its own, it must always be compiled AOT or JIT before execution.

CONFIG_BINFMT_MISC=y|m feature should be enabled for the kernel build.

:)


wow bro david ... you are really a wonderful person to share the knowledge with us ... thank you ... :)
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,299
wow bro david ... you are really a wonderful person to share the knowledge with us ... thank you ... :)
No problem. Knowledge sharing is also a challenge to me because I need to have the solution myself too to share with others and I tend to want to make sure the solution I provide is working and correct so that I don't mislead others. It is very beneficial to myself too, like a constant challenge as much as it is for the rest.

:)
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top