Speeding up top in a large YP environment
George M. Jones
george at CIS.OHIO-STATE.EDU
Wed Feb 14 08:08:45 AEST 1990
The following are the diffs to a change that I made to top.c that had
the effect of changing the startup time from 45-90 seconds to 6.
The problem was that top was using getpwent(3) to spin through most or
all of the 2000+ entries in our YP passsword file rather than simply
reading those entries that are needed via a call to getpwuid(3).
Enjoy. You millage may vary.
---George Jones
OSU Computer & Inf. Science 2036 Neil Ave.,Columbus,Ohio 43210. 614-292-7325
george at cis.ohio-state.edu or ...!osu-cis!george
X windows. You'd better sit down.
-----------------------------top.c.diff-----------------------------
138c138
< struct passwd *getpwuid();
---
> struct passwd *getpwent();
1174,1180c1174,1182
< if ((pwd = getpwuid(uid)) == NULL)
< {
< fprintf(stderr, "getpwuid(%d) failed\n", uid);
< quit(11);
< }
<
< return(enter_user(pwd->pw_uid, pwd->pw_name));
---
> while ((pwd = getpwent()) != NULL)
> {
> last_index = enter_user(pwd->pw_uid, pwd->pw_name);
> if (pwd->pw_uid == uid)
> {
> return(last_index);
> }
> }
> return(enter_user(uid, itoa7(uid)));
More information about the Comp.sources.bugs
mailing list