Soft, mis arvestab teo tööaega

#include <stdio.h>
#include <sys/io.h>
#include <unistd.h>
#include <time.h>

int main(void)
{
int addr=0x379;
int data, i, tsyklid, yhed;
FILE *out_file;
time_t seconds;
double protsent;
// requires EPP mode in BIOS
ioperm(addr,5,1);

while (1)
{
tsyklid=1500; // 5 korda sekundis * 300 sekundit
yhed=0; // nullime loenduri

for (i=0;i<tsyklid;i++)
        {
                usleep(200*970); // ~20 millisekundit, s.o. 5 korda sekundis.
                data=( inb(addr) & 128 ) /128;
                if (data) yhed++;
        protsent= ( (double) yhed/ (double) tsyklid) * 100;
        seconds = time (NULL);
        time ( &seconds );
        out_file = fopen("/mnt/usb/loeb4.txt", "w"); // usb pulgal olevasse faili
                                                     // läheb siis protsent, mis näitab katla
                                                     // teo töötamist viimase 5 min jooksul
        fprintf (out_file,"%.2f\n", protsent);
        fclose(out_file);
        printf ( "protsent: %.2f  kell: %s\n", protsent, ctime (&seconds)  ); // see rida konsoolis debugimise tarvis.
}
return(0);
}

Tulemuseks on siis konsoolis:

protsent: 26.27 kell: Thu Feb 17 08:36:24 2011
protsent: 6.93 kell: Thu Feb 17 08:41:24 2011
protsent: 0.00 kell: Thu Feb 17 08:46:24 2011
protsent: 0.00 kell: Thu Feb 17 08:51:24 2011
protsent: 0.00 kell: Thu Feb 17 08:56:24 2011
protsent: 0.00 kell: Thu Feb 17 09:01:23 2011
protsent: 0.00 kell: Thu Feb 17 09:06:23 2011
protsent: 0.00 kell: Thu Feb 17 09:11:23 2011
protsent: 0.00 kell: Thu Feb 17 09:16:23 2011
protsent: 0.00 kell: Thu Feb 17 09:21:23 2011
protsent: 22.60 kell: Thu Feb 17 09:26:23 2011
protsent: 19.87 kell: Thu Feb 17 09:31:23 2011
protsent: 26.13 kell: Thu Feb 17 09:36:23 2011
protsent: 25.80 kell: Thu Feb 17 09:41:23 2011

Ja mainitud failis lihtsalt: 25.80

kola/lpt-soft.txt · Viimati muutnud: 2011/02/18 19:19 persoon alvar
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0