Chinaunix

标题: 请教一个内核编译选项的问题 [打印本页]

作者: wwjjtt    时间: 2009-01-17 09:51
标题: 请教一个内核编译选项的问题
各位大侠,CONFIG_BINFMT_MISC  定义为运行Java程序的自动运行是什么概念?此选项为Y时,Java程序就可以不用虚拟机直接运行吗?请高手帮忙解疑答惑,谢谢。
作者: scutan    时间: 2009-01-17 10:32
原帖由 wwjjtt 于 2009-1-17 09:51 发表
各位大侠,CONFIG_BINFMT_MISC  定义为运行Java程序的自动运行是什么概念?此选项为Y时,Java程序就可以不用虚拟机直接运行吗?请高手帮忙解疑答惑,谢谢。



应该是说在内核中支持某些二进制的程序格式,
CONFIG_BINFMT_MISC:                                                     │
  │                                                                         │
  │ If you say Y here, it will be possible to plug wrapper-driven binary    │
  │ formats into the kernel. You will like this especially when you use     │
  │ programs that need an interpreter to run like Java, Python, .NET or     │
  │ Emacs-Lisp. It's also useful if you often run DOS executables under     │
  │ the Linux DOS emulator DOSEMU (read the DOSEMU-HOWTO, available from    │
  │ <http://www.tldp.org/docs.html#howto>). Once you have                   │
  │ registered such a binary class with the kernel, you can start one of    │
  │ those programs simply by typing in its name at a shell prompt; Linux    │
  │ will automatically feed it to the correct interpreter.


但并不是说只选进去就可以运行JAVA这些了,仍然需要安装JDK这些的。在内核文档Documentation/java.txt中讲到:
Java(tm) Binary Kernel Support for Linux v1.03
               ----------------------------------------------
Linux beats them ALL! While all other OS's are TALKING about direct support of Java Binaries in the OS, Linux is doing it!
You can execute Java applications and Java Applets just like any other program after you have done the following:
1) You MUST FIRST install the Java Developers Kit for Linux. The Java on Linux HOWTO gives the details on getting and
   installing this. This HOWTO can be found at:
        ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/Java-HOWTO
   You should also set up a reasonable CLASSPATH environment
   variable to use Java applications that make use of any
   nonstandard classes (not included in the same directory
   as the application itself).
2) You have to compile BINFMT_MISC either as a module or into the kernel (CONFIG_BINFMT_MISC) and set it up properly.
   If you choose to compile it as a module, you will have
   to insert it manually with modprobe/insmod, as kmod
   cannot easily be supported with binfmt_misc.
   Read the file 'binfmt_misc.txt' in this directory to know
   more about the configuration process.

后面省略


另外,还可以参考一下内核文档
Documentaton/binfmt_misc.txt
作者: scutan    时间: 2009-01-17 10:36
在《Linux内核源代码情景分析》中第四章第4节讲到了内核在执行程序时如何去查看这个程序的格式,然后再采取相应的执行方式。
作者: wwjjtt    时间: 2009-01-17 10:53
标题: 回复 #3 scutan 的帖子
谢谢法师提醒。我再去看看书。
作者: wwjjtt    时间: 2009-01-17 10:59
标题: 回复 #2 scutan 的帖子
版主法师,我自己做了一个文件系统,并且自己的内核也跑起来了,此选项并没有编译进内核,但是我在移植了一个Java虚拟机到文件系统之后,Java程序也是可以运行的,不知道这个选项是不是在进行java应用时必须那?
作者: ynchnluiti    时间: 2009-01-17 18:43
原帖由 wwjjtt 于 2009-1-17 10:59 发表
我自己做了一个文件系统,并且自己的内核也跑起来了,此选项并没有编译进内核,但是我在移植了一个Java虚拟机到文件系统之后,Java程序也是可以运行的,...

很牛
作者: scutan    时间: 2009-01-17 22:33
原帖由 wwjjtt 于 2009-1-17 10:59 发表
版主法师,我自己做了一个文件系统,并且自己的内核也跑起来了,此选项并没有编译进内核,但是我在移植了一个Java虚拟机到文件系统之后,Java程序也是可以运行的,不知道这个选项是不是在进行java应用时必须那? ...


你执行java程序时是怎样执行的?
java yourclass
还是
./yourclass
作者: wwjjtt    时间: 2009-01-19 10:14
标题: 回复 #7 scutan 的帖子
我是用java myclass执行的,你的意思是如果这个选项被选中了,那么就可以直接用./myclass来执行了吗? 我做个试验来看看。
作者: scutan    时间: 2009-01-19 10:32
原帖由 wwjjtt 于 2009-1-19 10:14 发表
我是用java myclass执行的,你的意思是如果这个选项被选中了,那么就可以直接用./myclass来执行了吗? 我做个试验来看看。


嗯,按照文档的说明来看,应该是的。
你看我二楼贴的:

                                                                         Once you have                   │
  │ registered such a binary class with the kernel, you can start one of    │
  │ those programs simply by typing in its name at a shell prompt; Linux    │
  │ will automatically feed it to the correct interpreter.

作者: scutan    时间: 2009-01-19 10:33
原帖由 wwjjtt 于 2009-1-19 10:14 发表
我是用java myclass执行的,你的意思是如果这个选项被选中了,那么就可以直接用./myclass来执行了吗? 我做个试验来看看。


有了结果也分享一下啊。
作者: wwjjtt    时间: 2009-01-19 15:07
标题: 回复 #10 scutan 的帖子
搞了一天试验,发现其实这个东西的运行过程是这样的,参考Documentation/binmft_misc.txt和Documentation/java.txt文档,mount  binmft_misc文件系统,然后配置这个系统,再编写一个C文件和一个脚本文件。最后可以直接使用./Myclass.class来执行Java程序,同样的,WINDOWS的exe程序也可以通过这种步骤实现,但是仔细研究这个过程,事实上Java的执行过程还是通过脚本和C文件得到相应的类名,又传递给Java虚拟机装载程序来执行的。总感觉这个配置好像没有太大用处。就是把Myclass.class转换并传递到Java虚拟机装载程序了。另外又碰上一个新问题。怎样可以让脚本文件通过 ./Myscript 方式执行?我在busybox下的shell是 ash。
作者: wwjjtt    时间: 2009-01-19 15:19
标题: 回复 #11 wwjjtt 的帖子
已经搞明白脚本的运行了。把我的脚本文件开头的#!/bin/bash更为#!/bin/sh就可以了。庆祝一下:
# ./Hello.class
javawrapper start
excute Hello class
Hello World!
Thank you!





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2