/** * Compile with: * valac --pkg=glib-2.0 cpu.vala * * Get number of core processor. **/ private static string nb_cpu (string data) { string[] tokens; string cores = null; tokens = data.split (": "); if (tokens.length == 2) { cores = tokens[1]; } return cores; } public static int main (string[] argv) { string cmd = "/sbin/sysctl hw.ncpu"; string cores; string std_err = null; int status; try { GLib.Process.spawn_command_line_sync (cmd, out cores, out std_err, out status); if (status == 0) { stdout.printf ("%s", nb_cpu (cores)); } } catch (GLib.SpawnError e) { stderr.printf ("Error: %s\n", e.message); } return 0; }