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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #include <math.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <sys/time.h>
  8. #include <sys/types.h>
  9. float exec_cmd(char *cmd)
  10. {
  11. FILE* fp;
  12. char* command;
  13. char* line;
  14. char* result;
  15. line = malloc(200 * sizeof(char));
  16. command = malloc(200 * sizeof(char));
  17. strcpy(command, cmd);
  18. fp = popen(command,"r");
  19. while((fgets(line, 60, fp)))
  20. {
  21. result = line;
  22. }
  23. return atof(result);
  24. }
  25. long long current_timestamp() {
  26. struct timeval te;
  27. gettimeofday(&te, NULL); // get current time
  28. long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
  29. // printf("milliseconds: %lld\n", milliseconds);
  30. return milliseconds;
  31. }
  32. float main()
  33. {
  34. float freq = exec_cmd("cat /proc/cpuinfo | grep \"cpu MHz\" | awk '{s+=$4} END {printf \"%0.3f\", s}'");
  35. int cpus = exec_cmd("cat /proc/cpuinfo | grep processor | wc -l");
  36. float core = exec_cmd("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage \"\"}'");
  37. int ram = exec_cmd("free -mt | grep Total: | awk '{s+=$3} END {printf \"%d\", s}'");
  38. int pid = getpid();
  39. printf("\nRamdy 0.1\n");
  40. printf("\n-------------------------\n");
  41. printf("\nTimestamp: %lld \n", current_timestamp());
  42. printf("\nPid: %d \n", pid);
  43. printf("\nFreq: %.6f \n", freq);
  44. printf("\nCpus: %d \n", cpus);
  45. printf("\nRam: %d \n", ram);
  46. printf("\nCore: %.6f \n", core);
  47. printf("\n----------\n");
  48. int date = (7 * (getpid() * current_timestamp()) + 3) % 1000;
  49. int cpur = (7 * (int)(freq * ram) + 3 ) % 1000;
  50. float result = (100 * (date * cpur)) / 998001;
  51. printf("\nDate: %d\n", date);
  52. printf("\nCpu: %d\n", cpur);
  53. printf("\nResult: %.6f\n", result);
  54. return result;
  55. }