2 * Filename: cpu-screen.c
3 * Purpose: output current / available cpu frequence (useful for integration into GNU screen)
4 * Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 * Bug-Reports: see http://grml.org/bugs/
6 * License: This file is licensed under the GPL v2.
7 *******************************************************************************/
15 static int cpu_cur_frequency(void)
18 char puffer[LINE_LEN];
20 fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
22 printf("[ cpufreq n/a ]\n");
26 while(fgets(puffer, LINE_LEN, fp)){
27 if ((nl = strchr(puffer,'\n')))
29 int value = atoi(puffer);
31 fprintf(stdout, "%u", value);
39 static int cpu_max_frequency(void)
42 char puffer[LINE_LEN];
43 fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
48 while(fgets(puffer, LINE_LEN, fp)){
49 int value = atoi(puffer);
51 fprintf(stdout, "%u\n", value);
59 // function inspired by cpufreq-info.c of cpufrequtils-0.4 by Dominik Brodowski
60 static int count_cpus(void)
65 unsigned int cpunr = 0;
67 fp = fopen("/proc/stat", "r");
68 // assume "1" cpu if we can't count it
74 fgets(value, LINE_LEN, fp);
75 if (strlen(value) < (LINE_LEN - 2))
77 if (strstr(value, "cpu "))
79 if (sscanf(value, "cpu%d ", &cpunr) != 1)
96 printf("%d * ", cpus);
99 ret = cpu_cur_frequency();
102 ret = cpu_max_frequency();