Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag -f to display all files from the monitored processes #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ signed char flag_throughput = 0;
signed char flag_monitor = 0;
signed char flag_monitor_continuous = 0;
signed char flag_open_mode = 0;
signed char flag_full_display = 0;
double throughput_wait_secs = 1;

WINDOW *mainwin;
Expand Down Expand Up @@ -755,10 +756,11 @@ static struct option long_options[] = {
{"pid", required_argument, 0, 'p'},
{"ignore-file", required_argument, 0, 'i'},
{"open-mode", required_argument, 0, 'o'},
{"full-display", no_argument, 0, 'f'},
{0, 0, 0, 0}
};

static char *options_string = "vqdwmMha:c:p:W:i:o:";
static char *options_string = "vqdwmMha:c:p:W:i:o:f";
int c,i;
int option_index = 0;
char *rp;
Expand Down Expand Up @@ -798,6 +800,7 @@ while(1) {
printf(" -p --pid id monitor only this process ID (ex: `pidof firefox`)\n");
printf(" -i --ignore-file file do not report process if using file\n");
printf(" -o --open-mode {r|w} report only files opened for read or write\n");
printf(" -f --full-display display all files opened by all processes (max %d)\n", MAX_RESULTS);
printf(" -v --version show program version and exit\n");
printf(" -h --help display this help and exit\n");
printf("\n\n");
Expand Down Expand Up @@ -873,6 +876,10 @@ while(1) {
}
break;

case 'f':
flag_full_display = 1;
break;

case '?':
default:
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -1027,11 +1034,15 @@ if (!pid_count) {
result_count = 0;

for (i = 0 ; i < pid_count ; i++) {
if (result_count >= MAX_RESULTS)
// Do not continue if there is no more space to store results.
break;

fd_count = find_fd_for_pid(pidinfo_list[i].pid, fdnum_list, MAX_FD_PER_PID);

max_size = 0;

// let's find the biggest opened file
// Iterate through all FDs
for (j = 0 ; j < fd_count ; j++) {
get_fdinfo(pidinfo_list[i].pid, fdnum_list[j], &fdinfo);

Expand All @@ -1040,12 +1051,26 @@ for (i = 0 ; i < pid_count ; i++) {
if (flag_open_mode == PM_WRITE && fdinfo.mode != PM_WRITE && fdinfo.mode != PM_READWRITE)
continue;

if (fdinfo.size > max_size) {
if (flag_full_display && result_count < MAX_RESULTS && fdinfo.size > 0) {
// Save all results if the flag is set, unless there's too many results already.
results[result_count].pid = pidinfo_list[i];
results[result_count].fd = fdinfo;
results[result_count].hbegin = NULL;
results[result_count].hend = NULL;
results[result_count].hsize = 0;

result_count++;
} else if (fdinfo.size > max_size) {
// let's find the biggest opened file
biggest_fd = fdinfo;
max_size = fdinfo.size;
}
}

if (flag_full_display)
// Do not determine the biggest FD if the user requested all files.
continue;

if (!max_size) { // nothing found
// this display is the root of too many confusion for the users, let's
// remove it. And it does not play well with --i option.
Expand Down