- 论坛徽章:
- 0
|
-bash-3.00$ cc -o io io.c
"io.c", line 1: warning: invalid white space character in directive
"io.c", line 2: warning: invalid white space character in directive
"io.c", line 3: warning: invalid white space character in directive
"io.c", line 4: warning: invalid white space character in directive
"io.c", line 5: warning: invalid white space character in directive
"io.c", line 6: warning: invalid white space character in directive
Undefined first referenced
symbol in file
kstat_chain_update io.o
kstat_read io.o
kstat_open io.o
ld: fatal: Symbol referencing errors. No output written to io
代码:
#include <kstat.h>
#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#define SLEEPTIME 5
unsigned int sleep(unsigned int);
void my_io_display(char *, char *, kstat_io_t);
int main(int argc, char *argv[])
{
kstat_ctl_t *kc;
kstat_t *ksp;
kstat_io_t kio;
kc = kstat_open();
while(1) {
if(kstat_chain_update(kc))
fprintf(stderr, "<<State Changed>>n");
for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
if (ksp->ks_type == KSTAT_TYPE_IO && strcmp(ksp->ks_class,"disk") == 0) {
kstat_read(kc, ksp, &kio);
my_io_display(ksp->ks_name, ksp->ks_class, kio);
}
}
sleep(SLEEPTIME);
} /* while(1) */
}
void my_io_display(char *devname, char *class, kstat_io_t k)
{
printf("Name: %s Class: %sn",devname,class);
printf("tnumber of bytes read %lldn", k.nread);
printf("tnumber of bytes written %lldn", k.nwritten);
printf("tnumber of read operations %dn", k.reads);
printf("tnumber of write operations %dn", k.writes);
} |
|