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 * Latest change: Tue Mar 28 11:01:43 CEST 2006 [mika]
8 *******************************************************************************/
16 static int cpu_cur_frequency(void)
19 char puffer[LINE_LEN];
21 fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
23 printf("[ cpufreq n/a ]\n");
27 while(fgets(puffer, LINE_LEN, fp)){
28 if ((nl = strchr(puffer,'\n')))
30 int value = atoi(puffer);
32 fprintf(stdout, "%u", value);
40 static int cpu_max_frequency(void)
43 char puffer[LINE_LEN];
44 fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
49 while(fgets(puffer, LINE_LEN, fp)){
50 int value = atoi(puffer);
52 fprintf(stdout, "%u\n", value);
60 // function inspired by cpufreq-info.c of cpufrequtils-0.4 by Dominik Brodowski
61 static int count_cpus(void)
66 unsigned int cpunr = 0;
68 fp = fopen("/proc/stat", "r");
69 // assume "1" cpu if we can't count it
75 fgets(value, LINE_LEN, fp);
76 if (strlen(value) < (LINE_LEN - 2))
78 if (strstr(value, "cpu "))
80 if (sscanf(value, "cpu%d ", &cpunr) != 1)
97 printf("%d * ", cpus);
100 ret = cpu_cur_frequency();
103 ret = cpu_max_frequency();