[lkml]   [2000]   [Oct]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Subject/proc/loadavg on 2.2.x
    I have a program that reads and prints /proc/loadavg once per second
    (look below). Note that the file is reopened for each read operation.
    I'm mainly interested in the fourth value, i.e., the number of processes
    in the run queue. Its initial value is one. After starting a cpu-intensive
    background process, the value should go up to two, however, the value
    actually becomes four. When the background process is terminated, the
    value won't go down to one, either, it stays at three. When the monitoring
    program is restarted, the correct value is displayed; the same applies for
    'cat /proc/loadavg'. In summary, the strange behavior is observed only for
    processes opening and reading /proc/loadavg multiple times.

    The behavior occurs on stock 2.2.x kernels; on Redhat 2.2.16-22, the
    value printed while the background process is running toggles between
    two and four, when the background process is terminated, it toggles
    between one and three. 2.0.36 behaves as expected.

    - Urs

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/time.h>
    #include <fcntl.h>

    #define LINUX_LDAV_FILE "/proc/loadavg"

    int main()
    FILE *file;
    int count;
    char ldavgbuf[41];

    while(1) {
    file = fopen (LINUX_LDAV_FILE, "r");
    if (!(file))
    return -1;
    memset(ldavgbuf, 0, 41);
    count = fread (ldavgbuf, 1, 40, file);
    (void) fclose (file);
    if (count <= 0)
    return -1;
    fprintf(stderr,"%s\n", ldavgbuf);
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 12:41    [W:0.019 / U:4.560 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site