• 判断是32位还是64位的CPU,CPU型号


    多少位:

    查看OS核心是32位还是64位
    SOLARIS:
    #isalist -v
    #isainfo -v
    #isainfo -b 

    AIX:

    bootinfo -K

    #bootinfo -k

    显示AIX系统内核是32位还是64

    #bootinfo -y
    显示机器硬件是32位还是64位

    #bootinfo -p
    显示机器是否支持64位内核(32:32位;chrp:64位)

    用man看看bootinfo的参数,就知道得更详细了

    #prtconf -k

    要显示CPU类型,例如是32位还是64位

    #prtconf -c

    HP-UX 
    getconf KERNEL_BITS

    ==============================================================

    CPU型号:

    You can get the os.arch property:

    String osArch =System.getProperty("os.arch");

    this will tell you the architecture of the OS, so not exactly the one of the VM.

    Sun's JREs have the following properties (values from my machine) that may be useful:

    sun.arch.data.model :32
    sun.cpu.isalist : pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86

    But have in mind that these will not work on VMs from other vendors. So you may want to find such properties of other VMs as well, so that you are not vendor-dependent.

    public class OpertingSystemInfo 
    {
      public static void main(String[] args)
      {
      String nameOS = "os.name";  
      String versionOS = "os.version";  
      String architectureOS = "os.arch";
      System.out.println("\n  The information about OS");
      System.out.println("\nName of the OS: " + 
      System.getProperty(nameOS));
      System.out.println("Version of the OS: " + 
      System.getProperty(versionOS));
      System.out.println("Architecture of THe OS: " + 
      System.getProperty(architectureOS));
      }
    }

    The output of the program is given below:

    C:\convert\rajesh\completed>javac OpertingSystemInfo.java
    C:\convert\rajesh\completed>java OpertingSystemInfo
        The information about OS
    Name of the OS: Windows 2000
    Version of the OS: 5.0
    Architecture of The OS: x86

    UNIX命令查看32/64位:

    file /bin/ls

    Enter java -version on the command line. If it's 64-bits it will say so, otherwise it's 32-bits.

    E.g.

    64 bits Oracle / Mac OS X

    $ java -version
    
    java version "1.6.0_20"Java(TM) SE RuntimeEnvironment(build 1.6.0_20-b02-279-10M3065)JavaHotSpot(TM)64-BitServer VM (build 16.3-b01-279, mixed mode)

    32 bits Oracle / Mac OS X (client)

    $ java -version
    
    java version "1.6.0_20"Java(TM) SE RuntimeEnvironment(build 1.6.0_20-b02-279-10M3065)JavaHotSpot(TM)Client VM (build 16.3-b01-279, mixed mode, sharing)

    32 bits Oracle / Mac OS X (server)

    $ java -server -version
    
    java version "1.6.0_20"Java(TM) SE RuntimeEnvironment(build 1.6.0_20-b02-279-10M3065)JavaHotSpot(TM)Server VM (build 16.3-b01-279, mixed mode)

    64 bits OpenJDK Ubuntu

    $ java -version
    
    java version "1.6.0_20"OpenJDKRuntimeEnvironment(IcedTea61.9.1)(6b20-1.9.1-1ubuntu3)OpenJDK64-BitServer VM (build 17.0-b16, mixed mode)

    32 bits Soylatte Mac OS X

    $ java -version
    
    java version "1.6.0_03-p3"Java(TM) SE RuntimeEnvironment(build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00)JavaHotSpot(TM)Client VM (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00, mixed mode)

    32 bits OpenJDK Mac OS X

    $ java -version
    
    openjdk version "1.6.0-internal"OpenJDKRuntimeEnvironment(build 1.6.0-internal-landonf_17_may_2009_13_58-b00)OpenJDKClient VM (build 11.0-b17, mixed mode)

    64 bits IBM Linux

    $ java -version
    
    java version "1.6.0"Java(TM) SE RuntimeEnvironment(build pxa6460sr8fp1-20100624_01(SR8 FP1))
    IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4Linux amd64-64 jvmxa6460sr8ifx-20100609

    *************************************************************************************************************
    java获取Mac地址:
    java通过ProcessBuilder执行本地shell命令 获取ip配置信息
    [java]代码库
    view sourceprint?
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Map;
     
    /**
     * 通过ProcessBuilder执行本地命令。此类用于创建操作系统进程。 获取本机的ip配置信息
     *
     * 每个进程生成器管理这些进程属性: (1)命令 是一个字符串列表,它表示要调用的外部程序文件及其参数(如果有) (2)环境 是从变量 到值
     * 的依赖于系统的映射。初始值是当前进程环境的一个副本. (3)工作目录。默认值是当前进程的当前工作目录,通常根据系统属性 user.dir 来命名.
     * (4)redirectErrorStream 属性。最初,此属性为 false, 意思是子进程的标准输出和错误输出被发送给两个独立的流, 这些流可以通过
     * Process.getInputStream() 和 Process.getErrorStream() 方法来访问。 如果将值设置为
     * true,标准错误将与标准输出合并。这使得关联错误消息和相应的输出变得更容易。 在此情况下,合并的数据可从
     * Process.getInputStream() 返回的流读取, 而从 Process.getErrorStream() 返回的流读取将直接到达文件尾。
     */
    public class UsingProcessBuilder {
     
        /**
         * 获取Windows系统下的网卡的MAC地址
         *
         * @return
         */
        public static String getPhysicalAddress() {
            Process p = null;
     
            try {
                // 执行ipconfig /all命令
                p = new ProcessBuilder("ipconfig", "/all").start();
           //非window平台
           p = new ProcessBuilder("ifconfig","-a").start(); }
    catch (IOException e) { return ""; } byte[] b = new byte[1024]; int readbytes = -1; StringBuffer sb = new StringBuffer(); // 读取进程输出值 InputStream in = p.getInputStream(); try { while ((readbytes = in.read(b)) != -1) { sb.append(new String(b, 0, readbytes)); } } catch (IOException e1) { } finally { try { in.close(); } catch (IOException e2) { } } return sb.toString(); } /** * 执行自定义的一个命令,该命令放在C:/temp下,并且需要2个环境变量的支持。 */ public static boolean executeMyCommand() { // 创建系统进程创建器 ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2"); // 获得进程的环境 Map<String, String> env = pb.environment(); // 设置和去除环境变量 env.put("VAR1", "myValue"); env.remove("VAR0"); env.put("VAR2", env.get("VAR1") + ";"); // 切换工作目录 pb.directory(new File("C:/temp")); try { // 得到进程实例 Process p = pb.start(); // 等待该进程执行完毕 if (p.waitFor() != 0) { // 如果进程运行结果不为0,表示进程是错误退出的 // 获得进程实例的错误输出 InputStream error = p.getErrorStream(); // do something } // 获得进程实例的标准输出 InputStream sdin = p.getInputStream(); } catch (IOException e) { } catch (InterruptedException e) { } return true; } public static void main(String[] args) { String address = UsingProcessBuilder.getPhysicalAddress(); System.out.println(address); } }
     
  • 相关阅读:
    NACBD
    周总结7
    周总结6
    团队题目——TD课程通
    移动端疫情展示
    周总结5
    每周总结4
    每周总结3
    每周总结2
    求最大子数组
  • 原文地址:https://www.cnblogs.com/duanxz/p/3115640.html
Copyright © 2020-2023  润新知