You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

65 lines
1.9 KiB

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
float exec_cmd(char *cmd)
{
FILE* fp;
char* command;
char* line;
char* result;
line = malloc(200 * sizeof(char));
command = malloc(200 * sizeof(char));
strcpy(command, cmd);
fp = popen(command,"r");
while((fgets(line, 60, fp)))
{
result = line;
}
return atof(result);
}
long long current_timestamp() {
struct timeval te;
gettimeofday(&te, NULL); // get current time
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
// printf("milliseconds: %lld\n", milliseconds);
return milliseconds;
}
float main()
{
float freq = exec_cmd("cat /proc/cpuinfo | grep \"cpu MHz\" | awk '{s+=$4} END {printf \"%0.3f\", s}'");
int cpus = exec_cmd("cat /proc/cpuinfo | grep processor | wc -l");
float core = exec_cmd("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage \"\"}'");
int ram = exec_cmd("free -mt | grep Total: | awk '{s+=$3} END {printf \"%d\", s}'");
int pid = getpid();
printf("\nRamdy 0.1\n");
printf("\n-------------------------\n");
printf("\nTimestamp: %lld \n", current_timestamp());
printf("\nPid: %d \n", pid);
printf("\nFreq: %.6f \n", freq);
printf("\nCpus: %d \n", cpus);
printf("\nRam: %d \n", ram);
printf("\nCore: %.6f \n", core);
printf("\n----------\n");
int date = (7 * (getpid() * current_timestamp()) + 3) % 1000;
int cpur = (7 * (int)(freq * ram) + 3 ) % 1000;
float result = (100 * (date * cpur)) / 998001;
printf("\nDate: %d\n", date);
printf("\nCpu: %d\n", cpur);
printf("\nResult: %.6f\n", result);
return result;
}