#include <termios.h>
#include <aul/aul.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/xattr.h>
static int verbose = 0;
static int doinfo = 0;
-static int timeout = 1;
+static int timeoutMicrosec = 500000; // 0.5 seconds
static int pid = -1;
static struct termios sterm;
free(pidname);
while(1) {
- time_t t = time(NULL);
char *stats[5];
char *pstats[18];
char *mt[3];
long pages;
long available;
+ struct timeval timeval;
+ int err, millisec;
+ time_t t = time(NULL);
+ err = gettimeofday(&timeval, NULL);
+ if (err != 0) {
+ timeval.tv_usec = 0;
+ timeoutMicrosec = 1000000; // 1 sec
+ }
+ millisec = (timeval.tv_usec + 500) / 1000;
+ if (millisec >= 1000)
+ {
+ ++t;
+ millisec = 0;
+ }
+
fseek(sstat, 0, SEEK_SET);
fflush(sstat);
slen = getline(&sline, &slen, sstat);
? (fstat.f_bsize / 1024) * fstat.f_bavail
: fstat.f_bavail / (1024 / fstat.f_bsize);
- printf("%ld %d" " %s %s %s" " %s %s" " %s %s %ld %ld\n",
- t, ncpu,
+ printf("%ld.%d %d" " %s %s %s" " %s %s" " %s %s %ld %ld\n",
+ t, millisec, ncpu,
stats[1], stats[3], stats[4], /* user system idle */
pstats[14 - 1], pstats[15 - 1], /* puser psystem */
mt[1], mf[1], available, pages * psize);
- sleep(timeout);
+ usleep(timeoutMicrosec);
}
return NULL;
}
case 'v': verbose++; break;
case 'l': ListApps(0); exit(0);
case 'i': doinfo = 1; break;
- case 't': timeout = atoi(optarg); break;
+ case 't': timeoutMicrosec = atoi(optarg) * 1000; break;
case 'w': isPipeOwner = 1; break;
default:
return -1;