forked from Bananymous/banan-os
meminfo: Add process command line to the output
This commit is contained in:
parent
b712c70c75
commit
f0b6844feb
|
@ -30,6 +30,43 @@ int main()
|
|||
if (!is_only_digits(proc_ent->d_name))
|
||||
continue;
|
||||
|
||||
printf("process: ");
|
||||
|
||||
{
|
||||
strcpy(path_buffer, proc_ent->d_name);
|
||||
strcat(path_buffer, "/cmdline");
|
||||
|
||||
int fd = openat(dirfd(proc), path_buffer, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("openat");
|
||||
continue;
|
||||
}
|
||||
|
||||
while (ssize_t nread = read(fd, path_buffer, sizeof(path_buffer) - 1))
|
||||
{
|
||||
if (nread == -1)
|
||||
{
|
||||
perror("read");
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < nread; i++)
|
||||
if (path_buffer[i] == '\0')
|
||||
path_buffer[i] = ' ';
|
||||
|
||||
path_buffer[nread] = '\0';
|
||||
|
||||
int written = 0;
|
||||
while (written < nread)
|
||||
written += printf("%s ", path_buffer + written);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
printf("\n pid: %s\n", proc_ent->d_name);
|
||||
|
||||
{
|
||||
strcpy(path_buffer, proc_ent->d_name);
|
||||
strcat(path_buffer, "/meminfo");
|
||||
|
||||
|
@ -45,14 +82,13 @@ int main()
|
|||
perror("read");
|
||||
else
|
||||
{
|
||||
printf("process:\n");
|
||||
printf(" pid: %s\n", proc_ent->d_name);
|
||||
printf(" vmem: %zu pages (%zu bytes)\n", meminfo.virt_pages, meminfo.page_size * meminfo.virt_pages);
|
||||
printf(" pmem: %zu pages (%zu bytes)\n", meminfo.phys_pages, meminfo.page_size * meminfo.phys_pages);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(proc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue