int main(int argc, char **argv) { long elaps[2]; ulong_t etime, stime; unsigned long mem; #ifdef uts float expand(); #else ulong_t expand(); #endif while (fread(&ab, sizeof(ab), 1, stdin) == 1) { if (!MYKIND(ab.ac_flag)) continue; pb.pt_uid = ab.ac_uid; CPYN(pb.pt_name, NULL); /* * approximate cpu P/NP split as same as elapsed time */ if ((etime = SECS(expand(ab.ac_etime))) == 0) etime = 1; stime = expand(ab.ac_stime) + expand(ab.ac_utime); mem = expand(ab.ac_mem); if(pnpsplit(ab.ac_btime, etime, elaps) == 0) { fprintf(stderr, "acctprc: could not calculate prime/non-prime hours\n"); exit(1); } pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime; pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0; pb.pt_cpu[1] = stime - pb.pt_cpu[0]; if (stime) pb.pt_mem = (mem + stime - 1) / stime; else pb.pt_mem = 0; /* unlikely */ enter(&pb); } output(); exit(0); }
int main(int argc, char **argv) { long elaps[2]; ulong_t etime, stime; unsigned long mem; ulong_t expand(); int ver; /* version of acct struct */ int aread(); if ((ur = (struct urec *) calloc(a_usize, sizeof (struct urec))) == NULL) { fprintf(stderr, "acctpr1: Cannot allocate memory\n"); exit(3); } urlast = ur; if ((sr = (struct srec *) calloc(a_ssize, sizeof (struct srec))) == NULL) { fprintf(stderr, "acctpr1: Cannot allocate memory\n"); exit(3); } while (--argc > 0) { if (**++argv == '-') switch(*++*argv) { } else { readctmp(*argv); } } if (fread((char *)&ab, sizeof(struct acct), 1, stdin) != 1) exit(1); else if (ab.ac_flag & AEXPND) ver = 2; /* 4.0 acct structure */ else ver = 1; /* 3.x acct structure */ rewind(stdin); while (aread(ver) == 1) { if (!MYKIND(ab.ac_flag)) continue; pb.pt_uid = ab.ac_uid; CPYN(pb.pt_name, getname(ab.ac_uid, ab.ac_tty, ab.ac_btime)); /* * approximate cpu P/NP split as same as elapsed time */ if ((etime = SECS(expand(ab.ac_etime))) == 0) etime = 1; stime = expand(ab.ac_stime) + expand(ab.ac_utime); mem = expand(ab.ac_mem); if(pnpsplit(ab.ac_btime, etime, elaps) == 0) { fprintf(stderr, "acctprc1: could not calculate prime/non-prime hours\n"); exit(1); } pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime; pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0; pb.pt_cpu[1] = stime - pb.pt_cpu[0]; if (stime) pb.pt_mem = (mem + stime - 1) / stime; else pb.pt_mem = 0; /* unlikely */ printf("%ld\t%.*s\t%lu\t%lu\t%u\n", pb.pt_uid, OUTPUT_NSZ, pb.pt_name, pb.pt_cpu[0], pb.pt_cpu[1], pb.pt_mem); } exit(0); }