- dir = opendir("/proc");
- if (!dir)
- perror_msg_and_die("Cannot open /proc");
-
- while ((next = readdir(dir)) != NULL) {
- FILE *status;
- char filename[READ_BUF_SIZE];
- char buffer[READ_BUF_SIZE];
- char name[READ_BUF_SIZE];
-
- /* If it isn't a number, we don't want it */
- if (!isdigit(*next->d_name))
- continue;
-
- sprintf(filename, "/proc/%s/status", next->d_name);
- if (! (status = fopen(filename, "r")) ) {
- continue;
- }
- if (fgets(buffer, READ_BUF_SIZE-1, status) == NULL) {
- fclose(status);
- continue;
- }
- fclose(status);
-
- /* Buffer should contain a string like "Name: binary_name" */
- sscanf(buffer, "%*s %s", name);
- if (strcmp(name, pidName) == 0) {
- pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
- pidList[i++]=strtol(next->d_name, NULL, 0);
+ pidList = xmalloc(sizeof(long));
+ while ((p = procps_scan(0)) != 0) {
+ if (strcmp(p->short_cmd, pidName) == 0) {
+ pidList=xrealloc( pidList, sizeof(long) * (i+2));
+ pidList[i++]=p->pid;