aboutsummaryrefslogtreecommitdiff
path: root/utils/psout.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/psout.c')
-rw-r--r--utils/psout.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/utils/psout.c b/utils/psout.c
index 7f2b0591..93667b28 100644
--- a/utils/psout.c
+++ b/utils/psout.c
@@ -1,6 +1,6 @@
/* Common output function for ps & w
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -31,7 +31,8 @@ psout (struct proc_stat_list *procs,
char *fmt_string, int posix_fmt, struct ps_fmt_specs *specs,
char *sort_key_name, int sort_reverse,
int output_width, int print_heading,
- int squash_bogus_fields, int squash_nominal_fields)
+ int squash_bogus_fields, int squash_nominal_fields,
+ int top)
{
error_t err;
struct ps_stream *output;
@@ -96,15 +97,17 @@ psout (struct proc_stat_list *procs,
error (5, err, "Can't make output stream");
if (print_heading)
- if (proc_stat_list_num_procs (procs) > 0)
- {
- err = ps_fmt_write_titles (fmt, output);
- if (err)
- error (0, err, "Can't print titles");
- ps_stream_newline (output);
- }
- else
- error (0, 0, "No applicable processes");
+ {
+ if (procs->num_procs > 0)
+ {
+ err = ps_fmt_write_titles (fmt, output);
+ if (err)
+ error (0, err, "Can't print titles");
+ ps_stream_newline (output);
+ }
+ else
+ error (1, 0, "No applicable processes");
+ }
if (output_width)
/* Try and restrict the number of output columns. */
@@ -117,6 +120,23 @@ psout (struct proc_stat_list *procs,
ps_fmt_set_output_width (fmt, output_width);
}
+ if (top)
+ /* Restrict output to the top TOP entries, if TOP is positive, or the
+ bottom -TOP entries, if it is negative. */
+ {
+ int filter (struct proc_stat *ps)
+ {
+ return --top >= 0;
+ }
+ if (top < 0)
+ {
+ top += procs->num_procs;
+ proc_stat_list_filter1 (procs, filter, 0, 1);
+ }
+ else
+ proc_stat_list_filter1 (procs, filter, 0, 0);
+ }
+
/* Finally, output all the processes! */
err = proc_stat_list_fmt (procs, fmt, output);
if (err)