systeminformation
systeminformation copied to clipboard
Add disk io information per process
Describe the solution you'd like
Add disk io information per process, perhaps in si.cpu()
or additional items in si.diskIO()
.
Describe alternatives you've considered Sorry I don't know much about windows APIs, so no solutions in windows.
For Linux, parsing /proc/[pid]/io would work.
For macOS, many solutions require sudo
(such as using iotop
, which also requires disabling SIP). I happen to find this solution which seems to work.
Below is a proof-of-concept using that solution:
#include <stdio.h>
#include <libproc.h>
#include <sys/resource.h>
int main() {
pid_t pid = 0;
printf("PID: ");
scanf("%d", &pid);
rusage_info_current rusage;
if (proc_pid_rusage(pid, RUSAGE_INFO_CURRENT, (void **)&rusage) == 0)
{
printf("Bytes read: %llu\n", rusage.ri_diskio_bytesread);
printf("Bytes written: %llu\n", rusage.ri_diskio_byteswritten);
}
return 0;
}
which gives me (10.15.1 Catalina with SIP enabled) the desired information, same as the one given in Activity Monitor:
PID: 179
Bytes read: 1109225472
Bytes written: 1863680
Additional context
We might have permission issues when accessing the disk io for certain processes. In that case, I think maybe it's acceptable to list the information as undefined
or something?