Re: How to determine system is idle

From: Eris Caffee (eris-redhat-list_at_eldalin.com)
Date: 08/27/05

  • Next message: Eris Caffee: "Re: X start automatically."
    Date: Sat, 27 Aug 2005 13:33:00 -0000 (UTC)
    To: "General Red Hat Linux discussion list" <redhat-list@redhat.com>
    
    

    > I have a query - Is there any wayout from which we would determine that
    > the linux machine had been idle for some time now, and in the meanwhile,
    > we could start some background process to do some housekeeping jobs - or
    > something of that sort.....

    Yes, this is very easy in Linux. There is a file on every Linux system
    named /proc/loadavg which contains the 1 minute, 5 minute, and 10 minute
    load averages for the system. The load is the number of processes that
    are waiting to run on the CPU, but which are blocked by a currently
    running process, and the X minute load average is the average number of
    processes that were waiting at any given instant over the past X minutes.
    So, for example, a 5 minute load average of 1.0 says that over the past 5
    minutes there was normally 1 process ready to run that was being blocked.

    To read the /proc/loadavg file from the command line, you can use the cat
    command, like this:

    [eris@mozart eris]$ cat /proc/loadavg
    0.43 0.28 0.14 2/124 30551

    This shows a 1 minute load average of 0.43, a 5 minute average of 0.28 and
    a 10 minute average of 0.14. It is generally best if the load is less
    than 1, so this shows that while my system is doing a few things, it is
    not overburdened. You will have to decide for yourself what it means for
    your system to be "idle", but I would say that if the load average is less
    than 0.10 then it is fairly idle.

    You can find documentation about the /proc/loadavg file, and the other
    files in the /proc directories, in Chapter 5 of the Red Hat Enterprise
    Linux Reference Guide, which you can find here:
    http://www.redhat.com/docs/manuals/enterprise/

    If you had a shell script and you wanted to read the load averages to
    determine whether or not to start the background job, you might use code
    like this:

    LoadAvg1=$(awk '{print $1 * 100}' /proc/loadavg)
    LoadAvg5=$(awk '{print $2 * 100}' /proc/loadavg)
    LoadAvg10=$(awk '{print $3 * 100}' /proc/loadavg)

    Threshhold=10 # This is .10 (the desired load average)
    times 100
    if [ $LoadAvg5 -le $Threshhold ] ; then
        do_housekeeping
    fi

    This will start the do_housekeeping program if the system has been idle
    for 5 minutes. Notice that I multiplied the real load averages and the
    Threshhold by 100 to convert everything to integers since shell variables
    cannot be decimal numbers.

    Eris Caffee

    -- 
    redhat-list mailing list
    unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
    https://www.redhat.com/mailman/listinfo/redhat-list
    

  • Next message: Eris Caffee: "Re: X start automatically."

    Relevant Pages

    • Re: Nice processes on Unix
      ... I feel a need to set the record straight for Linux, ... Waiting for a local block device usually will, ... The only point where this gets really strange is NFS: ... remember seeing stupidly high load averages on perfectly responsive ...
      (comp.lang.lisp)
    • Re: [SLE] memory management vs. top utility - SuSE 8.0
      ... I agree that linux memory mngmt ... Linux will page out "idle" pages of memory to free up RAM for caching, ...
      (SuSE)
    • Re: Whats causing idle ssh sessions to close?
      ... >> Linux and let the connection sit idle for a long time, ... >> times out and I get logged out of the Linux box. ... [roy@bonkers roy]$ echo $TMOUT ...
      (comp.unix.admin)
    • Re: /proc/loadavg disagrees with top and ps
      ... >>But top and ps both report a nearly idle system. ... How can I find out what is causing my system to be so busy? ... load averages below 1 mean system doesn't have any processes ...
      (Debian-User)
    • Re: Laptop battery life on FreeBSD
      ... Linux and I noticed a significant drop in my battery life (from ~3 ... I realize that Linux has their "tickless" ... CPU will throttle back whenever the system is idle. ... EPIA system has the following dev.cpu tree: ...
      (freebsd-questions)