Mercurial > hg > toybox
changeset 1738:783dc27590de draft
Minor ps refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 13 Mar 2015 21:33:34 -0500 |
parents | 052b608826a3 |
children | 1134cfb98257 |
files | toys/pending/ps.c |
diffstat | 1 files changed, 10 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/pending/ps.c Fri Mar 13 21:17:33 2015 -0500 +++ b/toys/pending/ps.c Fri Mar 13 21:33:34 2015 -0500 @@ -38,10 +38,8 @@ int width, position; }; -/* - * create list of header attributes taking care of -o (-o ooid=MOM..) - * and width of attributes. - */ +// create list of header attributes taking care of -o (-o ooid=MOM..) +// and width of attributes. static void list_add(struct header_list *data, char *c_data) { struct header_list *temp = TT.o, *new = xzalloc(sizeof(struct header_list)); @@ -168,10 +166,7 @@ free(temp); } -/* - * read command line taking care of in between NUL's - * in command line - */ +// read command line taking care of in between NUL's in command line static void read_cmdline(int fd, char *cmd_ptr) { int size = read(fd, cmd_ptr, BUFF_SIZE); //sizeof(cmd_buf) @@ -185,10 +180,8 @@ } } -/* - * get the processes stats and print the stats - * corresponding to header attributes. - */ +// get the processes stats and print the stats +// corresponding to header attributes. static void do_ps_line(int pid, int tid) { char *stat_buff = toybuf + BUFF_SIZE, *cmd_buff = toybuf + (2*BUFF_SIZE); @@ -351,7 +344,7 @@ free(name); } -//Do stats for threads (for -T option) +// Do stats for threads (for -T option) void do_ps_threads(int pid) { DIR *d; @@ -405,11 +398,10 @@ if (!(dp = opendir("/proc"))) perror_exit("opendir"); while ((entry = readdir(dp))) { - if (isdigit(*entry->d_name)) { - pid = atoi(entry->d_name); - do_ps_line(pid, 0); - if (toys.optflags & FLAG_T) do_ps_threads(pid); - } + if (!isdigit(*entry->d_name)) continue; + pid = atoi(entry->d_name); + do_ps_line(pid, 0); + if (toys.optflags & FLAG_T) do_ps_threads(pid); } closedir(dp);