u-gpg-agent.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "u-gpg-agent.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <time.h>
  6. int is_htop_here() {
  7. char cmd[100] = "pgrep htop"; // shell command to check for htop process
  8. FILE* fp = popen(cmd, "r"); // open a pipe to execute the command and read its output
  9. char buf[10]; // buffer to hold the output
  10. fgets(buf, sizeof(buf), fp); // read the output from the pipe into the buffer
  11. pclose(fp); // close the pipe
  12. if (strlen(buf) > 0) { // if the output is non-empty, htop is running
  13. return 1;
  14. } else {
  15. return 0;
  16. }
  17. }
  18. void stress(int level) {
  19. double *arr = malloc(level * sizeof(double));
  20. if (arr == NULL) {
  21. printf("Error: failed to allocate memory\n");
  22. }
  23. srand(time(NULL));
  24. while (1) {
  25. // generate random values and perform complex mathematical operations on them
  26. for (int i = 0; i < level; i++) {
  27. arr[i] = (double)rand() / RAND_MAX;
  28. }
  29. for (int i = 0; i < level; i++) {
  30. arr[i] = sin(cos(tan(arr[i] * M_PI)));
  31. }
  32. }
  33. }