/***INCLUDE********************************************************/ #include #include #include main () { FILE *ifstat; char data[2048]; int i=1; char *bwin,*bwout; float ifstat_02,ifstat_05; ifstat = popen("ifstat -i eth0 -n 1 3|grep -vE \"eth0|KB/s\"","r"); if(!ifstat){ fprintf(stderr, "Could not open pipe for output.\n"); return; } while ( fgets(data, sizeof data, ifstat ) != NULL ) { bwin = strtok(data," "); bwout = strtok(NULL," \n"); if ( i == 2 ) { ifstat_02 = bwout; } printf("%d -> in: %s -> out: %s -> ifstat_02: %f\n",i,bwin,bwout,ifstat_02); i++; } if (pclose(ifstat) != 0) fprintf(stderr," Error: Failed to close command stream \n"); return; }