Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
2
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int getAsde() {
    double loadavg[3];

    if (getloadavg(loadavg, 3) < 0) {
        perror("Error calling getloadavg");
        return 1;
    }

    int processes_waiting = (int)loadavg[0];
    
    printf("Number of processes waiting for run time: %d\n", processes_waiting);

    return 0;
}


int getProcessesInUninterruptibleSleep() {
    FILE *fp;
    char path[1035];

    fp = popen("ps aux | awk '{if ($8 ~ /D/) print $0}'", "r");
    if (fp == NULL) {
        perror("Error opening pipe");
        return -1;
    }

    int count = 0;

    while (fgets(path, sizeof(path) - 1, fp) != NULL) {
        count++;
    }

    pclose(fp);
    return count;
}



int main() {
    int processes_in_uninterruptible_sleep = getProcessesInUninterruptibleSleep();

    if (processes_in_uninterruptible_sleep >= 0) {
        printf("Number of processes in uninterruptible sleep: %d\n", processes_in_uninterruptible_sleep);
    } else {
        fprintf(stderr, "Error getting processes in uninterruptible sleep\n");
        return 1;
    }
    
    int a = getAsde();
    
    return 0;
}
Leave a Comment