Browse Source

more

master
Gustavo Adolfo Mesa Roldan 5 years ago
parent
commit
1c17e27f89
4 changed files with 80 additions and 9 deletions
  1. +15
    -9
      main.c
  2. +65
    -0
      main.c_old
  3. BIN
      randy
  4. +0
    -0
      run.sh

+ 15
- 9
main.c View File

@ -37,22 +37,28 @@ long long current_timestamp() {
float main()
{
float freq = exec_cmd("cat /proc/cpuinfo | grep \"cpu MHz\" | awk '{s+=$4} END {printf \"%0.3f\", s}'");
float cpus = exec_cmd("cat /proc/cpuinfo | grep processor | wc -l");
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 \"\"}'");
float ram = exec_cmd("free -mt | grep Total: | awk '{s+=$3} END {printf \"%d\", s}'");
float pid = getpid();
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 \nPid: %1.0f \nFreq: %.6f \nCpus: %.6f \nCore: %.6f \n", current_timestamp(), pid, freq, cpus,core);
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");
float date = (getpid() * current_timestamp()) % 1000;
int cpu = (int)(freq * ram) % 1000;
float result = (100 * (date * cpu)) / 998001;
int date = (7 * (getpid() * current_timestamp()) + 3) % 1000;
int cpur = (7 * (int)(freq * ram) + 3 ) % 1000;
printf("\nDate: %1.0f\n", date);
printf("\nCpu: %d\n", cpu);
float result = (100 * (date * cpur)) / 998001;
printf("\nDate: %d\n", date);
printf("\nCpu: %d\n", cpur);
printf("\nResult: %.6f\n", result);
return result;


+ 65
- 0
main.c_old View File

@ -0,0 +1,65 @@
#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 \"\"}'");
float 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;
}

BIN
randy View File


+ 0
- 0
run.sh View File


Loading…
Cancel
Save