@Override
	protected int detectTotalCpuPercent() throws Exception {
		Process process = null;
		try {

			// Execute command
			String cmd;
			if (command == null || command.isEmpty()) {
				String os = System.getProperty("os.name").toLowerCase();
				if (os.indexOf("win") >= 0) {

					// Windows command to query the actual CPU usage
					cmd = "wmic cpu get loadpercentage";

				} else {

					// Linux command to query the actual CPU usage
					cmd = "top -b -n2 -p 1 | fgrep \"Cpu(s)\" | tail -1 | awk -F'id,' -v prefix=\"$prefix\" "
							+ "'{ split($1, vs, \",\"); v=vs[length(vs)]; sub(\"%\", \"\", v); printf \"%s%.1f%%\n\", prefix, 100 - v }'";
				}
			} else {
				cmd = command;
			}
			process = Runtime.getRuntime().exec(cmd);
			BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
			StringBuilder tmp = new StringBuilder();
			String line = "";
			while ((line = reader.readLine()) != null) {
				tmp.setLength(0);
				char[] chars = line.toCharArray();
				for (char c : chars) {
					if (Character.isDigit(c)) {
						tmp.append(c);
					}
					if (c == ',' || c == '.') {
						tmp.append('.');
					}
				}
				if (tmp.length() > 0) {
					try {
						return (int) Double.parseDouble(tmp.toString());
					} catch (Exception ignored) {
					}
				}
			}
		} finally {
			if (process != null) {
				try {
					process.destroy();
				} catch (Exception ignored) {
				}
			}
		}
		return 0;
	}
@ Override protected int detectTotalCpuPercent ( ) throws Exception { Process process = null ; try { String cmd ; if ( command == null || command . isEmpty ( ) ) { String os = System . getProperty ( "os.name" ) . toLowerCase ( ) ; if ( os . indexOf ( "win" ) >= 0 ) { cmd = "wmic cpu get loadpercentage" ; } else { cmd = "top -b -n2 -p 1 | fgrep \"Cpu(s)\" | tail -1 | awk -F'id,' -v prefix=\"$prefix\" " + "'{ split($1, vs, \",\"); v=vs[length(vs)]; sub(\"%\", \"\", v); printf \"%s%.1f%%\n\", prefix, 100 - v }'" ; } } else { cmd = command ; } process = Runtime . getRuntime ( ) . exec ( cmd ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) ) ) ; StringBuilder tmp = new StringBuilder ( ) ; String line = "" ; while ( ( line = reader . readLine ( ) ) != null ) { tmp . setLength ( 0 ) ; char [ ] chars = line . toCharArray ( ) ; for ( char c : chars ) { if ( Character . isDigit ( c ) ) { tmp . append ( c ) ; } if ( c == ',' || c == '.' ) { tmp . append ( '.' ) ; } } if ( tmp . length ( ) > 0 ) { try { return ( int ) Double . parseDouble ( tmp . toString ( ) ) ; } catch ( Exception ignored ) { } } } } finally { if ( process != null ) { try { process . destroy ( ) ; } catch ( Exception ignored ) { } } } return 0 ; }
Returns the system CPU usage, in percents, between 0 and 100.

@return total CPU usage of the current OS