Skip to content
Snippets Groups Projects
Commit 0a283bc2 authored by Felix Moser's avatar Felix Moser
Browse files

adding service and refactoring

parent 8688dd31
No related branches found
No related tags found
No related merge requests found
File added
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
while (1) {
FILE *fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
if (!fp) {
perror("Fehler beim Öffnen der Frequenz-Datei");
return 1;
}
int freq_kHz;
fscanf(fp, "%d", &freq_kHz);
fclose(fp);
double freq_MHz = freq_kHz / 1000.0;
printf("CPU-Frequenz: %.2f MHz\n", freq_MHz);
}
return 0;
}
File added
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
while (1) {
FILE *fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (!fp) {
perror("Fehler beim Öffnen der Temperatur-Datei");
return 1;
}
int temp_mC;
fscanf(fp, "%d", &temp_mC);
fclose(fp);
double temp_C = temp_mC / 1000.0;
printf("CPU-Temperatur: %.2f°C\n", temp_C);
}
return 0;
}
#!/bin/bash
/usr/local/bin/cpu_temp &
/usr/local/bin/cpu_freq &
while true
do
sleep 3600
done
No preview for this file type
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void read_cpu_temp() {
FILE *file;
char buffer[1024];
char *temp_path = "/sys/class/thermal/thermal_zone0/temp";
file = fopen(temp_path, "r");
if (file == NULL) {
printf("Error opening file\n");
return;
}
if (fgets(buffer, sizeof(buffer), file) != NULL) {
long temp = atol(buffer) / 1000;
printf("CPU temperature: %ld C\n", temp);
} else {
printf("Error reading file\n");
}
fclose(file);
}
void read_cpu_frequency() {
FILE *file;
char buffer[1024];
char *freq_path = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq";
file = fopen(freq_path, "r");
if (file == NULL) {
printf("Error opening file\n");
return;
}
if (fgets(buffer, sizeof(buffer), file) != NULL) {
float freq = atol(buffer) / 1000000.0f;
printf("CPU frequency: %f GHz\n", freq);
} else {
printf("Error reading file\n");
}
fclose(file);
}
int main(void) { int main(void) {
read_cpu_temp();
read_cpu_frequency();
return 0; return 0;
} }
\ No newline at end of file
[Unit]
Description=Monitoring Processes
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/process_monitoring.sh
Restart=always
[Install]
WantedBy=multi-user.target
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment