[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] uptime



Jeg tror differencen stammer fra den måde watch virker på - den sover så
mange sekunder du beder den om, og så er den klar til at køre igen. Men
det kan der jo være så mange andre programmer som der også er, og det
tager lidt tid at spawne en ny process, så derfor kører den ikke hvert
sekund men lidt mere sjældent, hvorfor det ser ud som om at /proc/uptime
kører for hurtig.

Et lyn-cprogram, som giver samme resultat som /usr/bin/uptime kan se ud
således:

------ C-code begin ---
#include <stdio.h>

int main(void)
{
    int tsec, hsec; /* Total sec, 1/100 sec */
    int d, h, m;    /* Days, hours, mins, secs */
    char *fn = "/proc/uptime";
    FILE *f;

    if (!(f = fopen(fn, "r"))) {
        perror(fn); exit(-1);
    }
    fscanf(f, "%d.%d", &tsec, &hsec);
    d = tsec / (60*60*24);
    tsec -= d * (60*60*24);
    h = tsec / (60*60);
    tsec -= h * (60*60);
    m = tsec / 60;
    tsec -= m * 60;
    printf ("%d days, %d:%02d:%02d.%02d\n", d, h, m, tsec, hsec);
    return 0;
}
------ C-code end ---

Du skrev spørgsmålstegn efter "år", og det er jo lidt svært at definere
hvor langt et år er, når der regnes relativt - normaltr siger man 365.23
dage, men hvis man befinder sig i en lille omegn (<100 år) omkring år
2000, så er det nærmere 365.25, man kunne også kigge tilbage, og se om man
har paseret nogen skuddage, siden maskinen startede, og i bekræftende fald
så sige 366 for for antalet af gange man passerer en skuddag.

Endelig, så husk at der er en "fejl" i kerner før 2.2.0, som giver
overrun, omkring (så vidt jeg husker) 435 dage - men så vidt jeg har
forstået har det fatale konsekvenser for hele scheduleringen, så hele
maskinen kører vist ikke så godt. Nå men min record er kun små 300 dage,
inden jeg var nødt til at opdatere kernen.

v.h. Kurt



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *