- 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];
-
- /* Must skip ".." since that is outside /proc */
- if (strcmp(next->d_name, "..") == 0)
- continue;
-
- /* 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 = xmalloc(sizeof(long));
+ while ((p = procps_scan(0)) != 0) {
+ if (strcmp(p->short_cmd, pidName) == 0) {