static int get_usage(ProcFamilyClient& pfc, int argc, char* argv[]) { if (argc > 2) { fprintf(stderr, "error: argument synopsis for %s: [<pid>]\n", argv[0]); return 1; } pid_t pid = 0; if (argc == 2) { pid = atoi(argv[1]); if (pid == 0) { fprintf(stderr, "error: invalid pid: %s\n", argv[1]); return 1; } } ProcFamilyUsage pfu; bool success; if (!pfc.get_usage(pid, pfu, success)) { fprintf(stderr, "error: communication error with ProcD\n"); return 1; } if (!success) { fprintf(stderr, "error: %s command failed with ProcD\n", argv[0]); return 1; } printf("Number of Processes: %d\n", pfu.num_procs); printf("User CPU Time (s): %ld\n", pfu.user_cpu_time); printf("System CPU Time (s): %ld\n", pfu.sys_cpu_time); printf("CPU Percentage (%%): %f\n", pfu.percent_cpu); printf("Maximum Image Size (KB): %lu\n", pfu.max_image_size); printf("Total Image Size(KB): %lu\n", pfu.total_image_size); if (pfu.total_proportional_set_size_available) { printf("Proportional Set Size (KB): %lu\n", pfu.total_proportional_set_size); } if (pfu.block_read_bytes >= 0) printf("Bytes read from block devices (KB): %lu\n", pfu.block_read_bytes/1024); if (pfu.block_write_bytes >= 0) printf("Bytes written to block devices (KB): %lu\n", pfu.block_write_bytes/1024); return 0; }