Get operating System information with the SIGAR API

Source: Internet
Author: User

SIGAR (full Name System Information Gatherer and Reporter, which is the Systems information Collection Report), provides an open source, cross-platform API for collecting computer hardware and operating system information (the API's underlying interface is written in C). This article shows you how to get operating system information with the SIGAR API:

Package Com.ghj.packageoftest;import Java.net.inetaddress;import Org.hyperic.sigar.operatingsystem;import Org.hyperic.sigar.sigar;import org.hyperic.sigar.sigarexception;import org.hyperic.sigar.who;/** * with SIGAR API gets operating System Information * * @author Gaohuanjie */public class Ostool {public static void main (string[] args) throws Sigarexception { SIGAR SIGAR = new SIGAR ()///takes the name of the current operating system String hostname = ""; try {hostname = Inetaddress.getlocalhost (). GetHostName ( );} catch (Exception e) {hostname = Sigar.getnetinfo (). GetHostName (); SYSTEM.OUT.PRINTLN (hostname);//Get information about the current operating system operatingsystem OperatingSystem = Operatingsystem.getinstance (); System.out.println ("OperatingSystem arch:" + operatingsystem.getarch ());//Os kernel type: 386, 486, 586 et x86System.out.println ("OperatingSystem Cpuendian:" + Operatingsystem.getcpuendian ());//system.out.println (" OperatingSystem Datamodel: "+ Operatingsystem.getdatamodel ());//system.out.println (" OperatingSystem Description: "+ Operatingsystem.getdescription ());//SystemDescription System.out.println ("OperatingSystem machine:" + operatingsystem.getmachine ());//System.out.println (" OperatingSystem Name: "+ operatingsystem.getname ());//Os type System.out.println (" OperatingSystem patchlevel: "+ Operatingsystem.getpatchlevel ());//Os patch level SYSTEM.OUT.PRINTLN ("OperatingSystem Vendor:" + Operatingsystem.getvendor ());//Os Vendor System.out.println ("OperatingSystem vendorcodename:" + Operatingsystem.getvendorcodename ());//Supplier Code name SYSTEM.OUT.PRINTLN ("OperatingSystem vendorname:" + Operatingsystem.getvendorname ());//OS Vendor name System.out.println ("OperatingSystem vendorversion:" + Operatingsystem.getvendorversion ());//OS Vendor version System.out.println ("OperatingSystem version:" +    Operatingsystem.getversion ());//operating system version number//Get user information in the current system process table who whoarray [] = Sigar.getwholist (); if (Whoarray! = null) {        for (int i = 0; i < whoarray.length; i++) {who = Whoarray[i];        System.out.println ("\n~~~~~~~~~" + i + "~~~~~~~~~~~~"); System.out.println ("Who device:"+ Who.getdevice ());        System.out.println ("Who host:" + Who.gethost ());        System.out.println ("Who Time:" + who.gettime ()); System.out.println ("Who User:" + who.getuser ());//user name in the current system process table}}sigar.close ();}}
0 min Download Sample project

Get operating System information with the SIGAR API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.