replace /proc scanning code by more versatile one.

Use it where appropriate.
Stop scanning /etc/passwd *for every process*!!! (uid->username)
top: reduce memory usage - we won't save unneeded fields
from /proc info anymore. Downside: ~+250 bytes of code
This commit is contained in:
Denis Vlasenko
2006-11-05 00:43:51 +00:00
parent fa07680091
commit 459e4d6cf7
6 changed files with 329 additions and 172 deletions

View File

@@ -23,11 +23,11 @@ pid_t* find_pid_by_name(const char* procName)
{
pid_t* pidList;
int i = 0;
procps_status_t* p;
procps_status_t* p = NULL;
pidList = xmalloc(sizeof(*pidList));
while ((p = procps_scan(0)) != 0) {
if (strncmp(p->short_cmd, procName, COMM_LEN-1) == 0) {
while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM))) {
if (strncmp(p->comm, procName, sizeof(p->comm)-1) == 0) {
pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
pidList[i++] = p->pid;
}