procps/ps/display.c

649 lines
18 KiB
C
Raw Normal View History

2002-02-02 04:17:29 +05:30
/*
* display.c - display ps output
* Copyright 1998-2003 by Albert Cahalan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
2002-02-02 04:17:29 +05:30
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
2002-02-02 04:17:29 +05:30
#include <grp.h>
#include <locale.h>
#include <pwd.h>
#include <signal.h>
2002-02-02 04:17:29 +05:30
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
2002-02-02 04:17:29 +05:30
#include "../include/c.h"
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
#include "../include/fileutils.h"
#include "../include/signals.h"
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
#include "../include/xalloc.h"
#include "common.h"
2002-02-02 04:17:29 +05:30
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif
char *myname;
long Hertz;
2002-02-02 04:17:29 +05:30
/* just reports a crash */
static void signal_handler(int signo){
if(signo==SIGPIPE) _exit(0); /* "ps | head" will cause this */
/* fprintf() is not reentrant, but we _exit() anyway */
fprintf(stderr,
_("Signal %d (%s) caught by %s (%s).\n"),
2002-02-02 04:17:29 +05:30
signo,
2003-03-18 05:12:00 +05:30
signal_number_to_name(signo),
myname,
PACKAGE_VERSION
2002-02-02 04:17:29 +05:30
);
switch (signo) {
case SIGHUP:
case SIGUSR1:
case SIGUSR2:
exit(EXIT_FAILURE);
default:
error_at_line(0, 0, __FILE__, __LINE__, "%s", _("please report this bug"));
signal(signo, SIG_DFL); /* allow core file creation */
kill(getpid(), signo);
}
2002-02-02 04:17:29 +05:30
}
2002-11-27 05:54:01 +05:30
/////////////////////////////////////////////////////////////////////////////////////
2002-02-02 04:17:29 +05:30
#undef DEBUG
#ifdef DEBUG
void init_stack_trace(char *prog_name);
#include <ctype.h>
void hex_dump(void *vp){
char *charlist;
int i = 0;
int line = 45;
char *cp = (char *)vp;
while(line--){
printf("%8lx ", (unsigned long)cp);
charlist = cp;
cp += 16;
for(i=0; i<16; i++){
if((charlist[i]>31) && (charlist[i]<127)){
printf("%c", charlist[i]);
}else{
printf(".");
}
}
printf(" ");
for(i=0; i<16; i++) printf(" %2x",(unsigned int)((unsigned char)(charlist[i])));
printf("\n");
i=0;
}
}
2003-09-20 13:59:55 +05:30
static void show_tgid(char *s, int n, sel_union *data){
2002-02-02 04:17:29 +05:30
printf("%s ", s);
while(--n){
2003-09-20 13:59:55 +05:30
printf("%d,", data[n].tgid);
2002-02-02 04:17:29 +05:30
}
2003-09-20 13:59:55 +05:30
printf("%d\n", data[0].tgid);
2002-02-02 04:17:29 +05:30
}
static void show_uid(char *s, int n, sel_union *data){
struct passwd *pw_data;
printf("%s ", s);
while(--n){
pw_data = getpwuid(data[n].uid);
if(pw_data) printf("%s,", pw_data->pw_name);
else printf("%d,", data[n].uid);
}
pw_data = getpwuid(data[n].uid);
if(pw_data) printf("%s\n", pw_data->pw_name);
else printf("%d\n", data[n].uid);
}
static void show_gid(char *s, int n, sel_union *data){
struct group *gr_data;
printf("%s ", s);
while(--n){
gr_data = getgrgid(data[n].gid);
if(gr_data) printf("%s,", gr_data->gr_name);
else printf("%d,", data[n].gid);
}
gr_data = getgrgid(data[n].gid);
if(gr_data) printf("%s\n", gr_data->gr_name);
else printf("%d\n", data[n].gid);
}
static void show_tty(char *s, int n, sel_union *data){
printf("%s ", s);
while(--n){
printf("%d:%d,", (int)major(data[n].tty), (int)minor(data[n].tty));
}
printf("%d:%d\n", (int)major(data[n].tty), (int)minor(data[n].tty));
}
static void show_cmd(char *s, int n, sel_union *data){
printf("%s ", s);
while(--n){
printf("%.8s,", data[n].cmd);
}
printf("%.8s\n", data[0].cmd);
}
static void arg_show(void){
selection_node *walk = selection_list;
while(walk){
switch(walk->typecode){
case SEL_RUID: show_uid("RUID", walk->n, walk->u); break;
case SEL_EUID: show_uid("EUID", walk->n, walk->u); break;
case SEL_SUID: show_uid("SUID", walk->n, walk->u); break;
case SEL_FUID: show_uid("FUID", walk->n, walk->u); break;
case SEL_RGID: show_gid("RGID", walk->n, walk->u); break;
case SEL_EGID: show_gid("EGID", walk->n, walk->u); break;
case SEL_SGID: show_gid("SGID", walk->n, walk->u); break;
case SEL_FGID: show_gid("FGID", walk->n, walk->u); break;
case SEL_PGRP: show_pid("PGRP", walk->n, walk->u); break;
case SEL_PID : show_pid("PID ", walk->n, walk->u); break;
case SEL_PID_QUICK : show_pid("PID_QUICK ", walk->n, walk->u); break;
2003-02-09 13:01:11 +05:30
case SEL_PPID: show_pid("PPID", walk->n, walk->u); break;
2002-02-02 04:17:29 +05:30
case SEL_TTY : show_tty("TTY ", walk->n, walk->u); break;
case SEL_SESS: show_pid("SESS", walk->n, walk->u); break;
case SEL_COMM: show_cmd("COMM", walk->n, walk->u); break;
default: printf("Garbage typecode value!\n");
2002-02-02 04:17:29 +05:30
}
walk = walk->next;
}
}
#endif
2002-11-27 05:54:01 +05:30
//////////////////////////////////////////////////////////////////////////
2002-02-02 04:17:29 +05:30
/***** check the header */
/* Unix98: must not print empty header */
static void check_headers(void){
format_node *walk = format_list;
int head_normal = 0;
if(header_type==HEAD_MULTI){
header_gap = screen_rows-1; /* true BSD */
return;
}
if(header_type==HEAD_NONE){
lines_to_next_header = -1; /* old Linux */
return;
}
while(walk){
if(!*(walk->name)){
walk = walk->next;
continue;
}
if(walk->pr){
head_normal++;
walk = walk->next;
continue;
}
walk = walk->next;
}
if(!head_normal) lines_to_next_header = -1; /* how UNIX does --noheader */
}
2003-09-29 09:39:52 +05:30
static format_node *proc_format_list;
static format_node *task_format_list;
2003-09-29 09:39:52 +05:30
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
/***** munge lists and determine final needs */
2003-09-29 09:39:52 +05:30
static void lists_and_needs(void){
check_headers();
// only care about the difference when showing both
if(thread_flags & TF_show_both){
2003-09-29 09:39:52 +05:30
format_node pfn, tfn; // junk, to handle special case at begin of list
format_node *walk = format_list;
format_node *p_end = &pfn;
format_node *t_end = &tfn;
while(walk){
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
format_node *new = xmalloc(sizeof(format_node));
2003-09-29 09:39:52 +05:30
memcpy(new,walk,sizeof(format_node));
p_end->next = walk;
t_end->next = new;
p_end = walk;
t_end = new;
switch(walk->flags & CF_PRINT_MASK){
case CF_PRINT_THREAD_ONLY:
p_end->pr = pr_nop;
break;
case CF_PRINT_PROCESS_ONLY:
t_end->pr = pr_nop;
break;
default:
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
2003-09-29 09:39:52 +05:30
// FALL THROUGH
case CF_PRINT_AS_NEEDED:
case CF_PRINT_EVERY_TIME:
break;
}
walk = walk->next;
}
t_end->next = NULL;
p_end->next = NULL;
proc_format_list = pfn.next;
task_format_list = tfn.next;
}else{
proc_format_list = format_list;
task_format_list = format_list;
}
}
2003-09-29 09:39:52 +05:30
//////////////////////////////////////////////////////////////////////////
2002-02-02 04:17:29 +05:30
/***** fill in %CPU; not in libproc because of include_dead_children */
2002-10-10 05:10:30 +05:30
/* Note: for sorting, not display, so 0..0x7fffffff would be OK */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
static void value_this_proc_pcpu(proc_t *buf){
2002-10-10 05:10:30 +05:30
unsigned long long used_jiffies;
2002-02-02 04:17:29 +05:30
unsigned long pcpu = 0;
unsigned long long seconds;
2002-02-02 04:17:29 +05:30
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if(want_this_proc(buf)) {
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if(include_dead_children) used_jiffies = rSv(TICS_ALL_C, ull_int, buf);
else used_jiffies = rSv(TICS_ALL, ull_int, buf);
2003-10-20 05:07:47 +05:30
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
seconds = rSv(TIME_ELAPSED, ull_int, buf);
if(seconds) pcpu = (used_jiffies * 1000ULL / Hertz) / seconds;
2002-10-10 05:10:30 +05:30
// if xtra-procps-debug.h active, can't use PIDS_VAL as base due to assignment
buf->head[rel_extra].result.ul_int = pcpu;
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
}
2002-02-02 04:17:29 +05:30
}
/***** just display */
static void simple_spew(void){
struct pids_fetch *pidread;
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
proc_t *buf;
int i;
// -q option (only single SEL_PID_QUICK typecode entry expected in the list, if present)
if (selection_list && selection_list->typecode == SEL_PID_QUICK) {
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
unsigned *pidlist = xcalloc(selection_list->n, sizeof(unsigned));
for (i = 0; i < selection_list->n; i++)
pidlist[i] = selection_list->u[selection_list->n-i-1].pid;
pidread = procps_pids_select(Pids_info, pidlist, selection_list->n, PIDS_SELECT_PID);
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
free(pidlist);
} else {
enum pids_fetch_type which;
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
which = (thread_flags & (TF_loose_tasks|TF_show_task))
? PIDS_FETCH_THREADS_TOO : PIDS_FETCH_TASKS_ONLY;
pidread = procps_pids_reap(Pids_info, which);
}
if (!pidread) {
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
fprintf(stderr, _("fatal library error, reap\n"));
exit(EXIT_FAILURE);
2002-02-02 04:17:29 +05:30
}
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
2003-10-21 06:21:36 +05:30
switch(thread_flags & (TF_show_proc|TF_loose_tasks|TF_show_task)){
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
case TF_show_proc: // normal non-thread output
for (i = 0; i < pidread->counts->total; i++) {
buf = pidread->stacks[i];
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if (want_this_proc(buf))
show_one_proc(buf, proc_format_list);
2003-10-21 06:21:36 +05:30
}
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
break;
case TF_show_task: // -L and -T options
case TF_show_proc|TF_loose_tasks: // H option
for (i = 0; i < pidread->counts->total; i++) {
buf = pidread->stacks[i];
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if (want_this_proc(buf))
show_one_proc(buf, task_format_list);
2003-10-21 06:21:36 +05:30
}
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
break;
case TF_show_proc|TF_show_task: // m and -m options
procps_pids_sort(Pids_info, pidread->stacks
, pidread->counts->total, PIDS_TIME_START, PIDS_SORT_ASCEND);
procps_pids_sort(Pids_info, pidread->stacks
, pidread->counts->total, PIDS_ID_TGID, PIDS_SORT_ASCEND);
for (i = 0; i < pidread->counts->total; i++) {
buf = pidread->stacks[i];
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
next_proc:
if (want_this_proc(buf)) {
int self = rSv(ID_PID, s_int, buf);
show_one_proc(buf, proc_format_list);
for (; i < pidread->counts->total; i++) {
buf = pidread->stacks[i];
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if (rSv(ID_TGID, s_int, buf) != self) goto next_proc;
show_one_proc(buf, task_format_list);
}
}
2003-09-20 13:59:55 +05:30
}
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
break;
2002-02-02 04:17:29 +05:30
}
}
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
2002-02-02 04:17:29 +05:30
/***** forest output requires sorting by ppid; add start_time by default */
static void prep_forest_sort(void){
sort_node *tmp_list = sort_list;
const format_struct *incoming;
if(!sort_list) { /* assume start time order */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
incoming = search_format_array("ppid");
if(!incoming) { fprintf(stderr, _("could not find ppid\n")); exit(1); }
tmp_list = xmalloc(sizeof(sort_node));
tmp_list->reverse = PIDS_SORT_ASCEND;
2002-02-02 04:17:29 +05:30
tmp_list->typecode = '?'; /* what was this for? */
tmp_list->sr = incoming->sr;
tmp_list->next = sort_list;
sort_list = tmp_list;
}
/* this is required for the forest option */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
incoming = search_format_array("start_time");
if(!incoming) { fprintf(stderr, _("could not find start_time\n")); exit(1); }
tmp_list = xmalloc(sizeof(sort_node));
tmp_list->reverse = PIDS_SORT_ASCEND;
2002-02-02 04:17:29 +05:30
tmp_list->typecode = '?'; /* what was this for? */
tmp_list->sr = incoming->sr;
tmp_list->next = sort_list;
sort_list = tmp_list;
}
/* we rely on the POSIX requirement for zeroed memory */
2003-10-16 09:00:41 +05:30
static proc_t **processes;
2002-02-02 04:17:29 +05:30
/***** show pre-sorted array of process pointers */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
static void show_proc_array(int n){
2002-02-02 04:17:29 +05:30
proc_t **p = processes;
while(n--){
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
show_one_proc(*p, proc_format_list);
2002-02-02 04:17:29 +05:30
p++;
}
}
/***** show tree */
/* this needs some optimization work */
#define ADOPTED(x) 1
static void show_tree(const int self, const int n, const int level, const int have_sibling){
int i = 0;
if(level){
/* add prefix of "+" or "L" */
if(have_sibling) forest_prefix[level-1] = '+';
else forest_prefix[level-1] = 'L';
forest_prefix[level] = '\0';
}
2003-09-28 22:53:29 +05:30
show_one_proc(processes[self],format_list); /* first show self */
2002-02-02 04:17:29 +05:30
for(;;){ /* look for children */
if(i >= n) return; /* no children */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if(rSv(ID_PPID, s_int, processes[i]) == rSv(ID_PID, s_int, processes[self])) break;
2002-02-02 04:17:29 +05:30
i++;
}
if(level){
/* change our prefix to "|" or " " for the children */
if(have_sibling) forest_prefix[level-1] = '|';
else forest_prefix[level-1] = ' ';
forest_prefix[level] = '\0';
}
for(;;){
int self_pid;
int more_children = 1;
if(i >= n) break; /* over the edge */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
self_pid=rSv(ID_PID, s_int, processes[self]);
2002-02-02 04:17:29 +05:30
if(i+1 >= n)
more_children = 0;
else
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if(rSv(ID_PPID, s_int, processes[i+1]) != self_pid) more_children = 0;
2002-02-02 04:17:29 +05:30
if(self_pid==1 && ADOPTED(processes[i]) && forest_type!='u')
show_tree(i++, n, level, more_children);
else
show_tree(i++, n, level+1, more_children);
if(!more_children) break;
}
/* chop prefix that children added -- do we need this? */
forest_prefix[level] = '\0';
}
/***** show forest */
static void show_forest(const int n){
int i = n;
int j;
while(i--){ /* cover whole array looking for trees */
j = n;
while(j--){ /* search for parent: if none, i is a tree! */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
if(rSv(ID_PID, s_int, processes[j]) == rSv(ID_PPID, s_int, processes[i])) goto not_root;
2002-02-02 04:17:29 +05:30
}
show_tree(i,n,0,0);
not_root:
2002-10-02 06:03:56 +05:30
;
2002-02-02 04:17:29 +05:30
}
/* don't free the array because it takes time and ps will exit anyway */
}
#if 0
2003-10-20 05:07:47 +05:30
static int want_this_proc_nop(proc_t *dummy){
(void)dummy;
return 1;
}
#endif
2003-10-20 05:07:47 +05:30
2002-02-02 04:17:29 +05:30
/***** sorted or forest */
static void fancy_spew(void){
struct pids_fetch *pidread;
enum pids_fetch_type which;
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
proc_t *buf;
int i, n = 0;
which = (thread_flags & TF_loose_tasks)
? PIDS_FETCH_THREADS_TOO : PIDS_FETCH_TASKS_ONLY;
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
pidread = procps_pids_reap(Pids_info, which);
if (!pidread || !pidread->counts->total) {
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
fprintf(stderr, _("fatal library error, reap\n"));
exit(EXIT_FAILURE);
}
processes = xcalloc(pidread->counts->total, sizeof(void*));
for (i = 0; i < pidread->counts->total; i++) {
buf = pidread->stacks[i];
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
value_this_proc_pcpu(buf);
if (want_this_proc(buf))
processes[n++] = buf;
}
if (n) {
if(forest_type) prep_forest_sort();
while(sort_list) {
procps_pids_sort(Pids_info, processes, n, sort_list->sr, sort_list->reverse);
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
sort_list = sort_list->next;
}
if(forest_type) show_forest(n);
else show_proc_array(n);
2003-10-20 05:07:47 +05:30
}
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
free(processes);
2002-02-02 04:17:29 +05:30
}
static void arg_check_conflicts(void)
{
int selection_list_len;
int has_quick_pid;
selection_node *walk = selection_list;
has_quick_pid = 0;
selection_list_len = 0;
while (walk) {
if (walk->typecode == SEL_PID_QUICK) has_quick_pid++;
walk = walk->next;
selection_list_len++;
}
/* -q doesn't allow multiple occurrences */
if (has_quick_pid > 1) {
fprintf(stderr, "q/-q/--quick-pid can only be used once.\n");
exit(1);
}
/* -q doesn't allow combinations with other selection switches */
if (has_quick_pid && selection_list_len > has_quick_pid) {
fprintf(stderr, "q/-q/--quick-pid cannot be combined with other selection options.\n");
exit(1);
}
/* -q cannot be used with forest type listings */
if (has_quick_pid && forest_type) {
fprintf(stderr, "q/-q/--quick-pid cannot be used together with forest type listings.\n");
exit(1);
}
/* -q cannot be used with sort */
if (has_quick_pid && sort_list) {
fprintf(stderr, "q/-q,--quick-pid cannot be used together with sort options.\n");
exit(1);
}
/* -q cannot be used with -N */
if (has_quick_pid && negate_selection) {
fprintf(stderr, "q/-q/--quick-pid cannot be used together with negation switches.\n");
exit(1);
}
}
2002-02-02 04:17:29 +05:30
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
static void finalize_stacks (void)
{
format_node *f_node;
sort_node *s_node;
#if (PIDSITEMS < 60)
# error PIDSITEMS (common.h) should be at least 60!
#endif
/* first, ensure minimum result structures for items
which may or may not actually be displayable ... */
Pids_index = 0;
// needed by for selections
chkREL(CMD)
chkREL(ID_EGID)
chkREL(ID_EUID)
chkREL(ID_FGID)
chkREL(ID_FUID)
chkREL(ID_PID)
chkREL(ID_PPID)
chkREL(ID_RGID)
chkREL(ID_RUID)
chkREL(ID_SESSION)
chkREL(ID_SGID)
chkREL(ID_SUID)
chkREL(ID_TGID)
chkREL(STATE)
chkREL(TTY)
// needed to creata an enhanced 'stat/state'
chkREL(ID_PGRP)
chkREL(ID_TPGID)
chkREL(NICE)
chkREL(NLWP)
chkREL(RSS)
chkREL(VM_RSS_LOCKED)
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
// needed with 's' switch, previously assured
chkREL(SIGBLOCKED)
chkREL(SIGCATCH)
chkREL(SIGIGNORE)
chkREL(SIGNALS)
chkREL(SIGPENDING)
// needed with loss of defunct 'cook_time' macros
chkREL(TICS_ALL)
chkREL(TICS_ALL_C)
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
chkREL(TIME_ALL)
chkREL(TIME_ELAPSED)
chkREL(TIME_START)
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
// special items with 'extra' used as former pcpu
chkREL(extra)
chkREL(noop)
// now accommodate any results not yet satisfied
f_node = format_list;
while (f_node) {
(*f_node->pr)(NULL, NULL);
f_node = f_node->next;
}
s_node = sort_list;
while (s_node) {
if (s_node->xe) (*s_node->xe)(NULL, NULL);
s_node = s_node->next;
}
procps_pids_reset(Pids_info, Pids_items, Pids_index);
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
}
2002-02-02 04:17:29 +05:30
/***** no comment */
int main(int argc, char *argv[]){
atexit(close_stdout);
myname = strrchr(*argv, '/');
if (myname) ++myname; else myname = *argv;
Hertz = procps_hertz_get();
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
2004-11-05 02:20:59 +05:30
2002-02-02 04:17:29 +05:30
#ifdef DEBUG
init_stack_trace(argv[0]);
#else
do {
struct sigaction sa;
int i = 32;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = signal_handler;
sigfillset(&sa.sa_mask);
while(i--) switch(i){
default:
sigaction(i,&sa,NULL);
case 0:
case SIGCONT:
2002-02-02 04:17:29 +05:30
case SIGINT: /* ^C */
2005-01-06 02:04:51 +05:30
case SIGTSTP: /* ^Z */
2005-01-06 05:43:12 +05:30
case SIGTTOU: /* see stty(1) man page */
2002-02-02 04:17:29 +05:30
case SIGQUIT: /* ^\ */
case SIGPROF: /* profiling */
case SIGKILL: /* can not catch */
case SIGSTOP: /* can not catch */
case SIGWINCH: /* don't care if window size changes */
2002-10-02 06:03:56 +05:30
;
2002-02-02 04:17:29 +05:30
}
} while (0);
#endif
reset_global(); /* must be before parser */
arg_parse(argc,argv);
/* check for invalid combination of arguments */
arg_check_conflicts();
2002-02-02 04:17:29 +05:30
/* arg_show(); */
trace("screen is %ux%u\n",screen_cols,screen_rows);
2002-02-02 04:17:29 +05:30
/* printf("sizeof(proc_t) is %d.\n", sizeof(proc_t)); */
trace("======= ps output follows =======\n");
2002-02-02 04:17:29 +05:30
init_output(); /* must be between parser and output */
2003-09-29 09:39:52 +05:30
lists_and_needs();
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
finalize_stacks();
2002-02-02 04:17:29 +05:30
if(forest_type || sort_list) fancy_spew(); /* sort or forest */
else simple_spew(); /* no sort, no forest */
2003-09-28 22:53:29 +05:30
show_one_proc((proc_t *)-1,format_list); /* no output yet? */
ps: exploit those new <pids> task/threads capabilities This commit represents the ps transition to the <pids> 'stacks' interface. While an effort to minimize impact on existing code was made (as with a disguised proc_t) the changes were still extensive. Along the way, a few modifications beyond simply conversion were also made. ------------------------------------------------------ Here's a brief overview the design of this conversion: . The need to satisfy relative enum requirements could not easily have been made table driven since any entry in the format_array might require several <pids> items in support. So I decided to allow every print function to contribute its own relative enums once the decision as to exactly what will be printed had been finalized. . A similar approach was taken for sorting, since it's possible to have sort keys that will not be displayed. Here, I relied on the existing print extensions above. . In summary, just prior to printing ps walks thru two lists one time (the format_list & sort_list) and calls each print function. That function does not print, but sets its required enum if necessary. Later, when those same functions are called repeatedly for every printed line, the only overhead will be an if test and branch. ------------------------------------------------------ Below is a summary of major changes beyond conversion: . Sorts are now the responsibility of the library. And therefore the total # of sortable fields substantially increased without effort. Additionally, several quirky fields remain as sortable, even though they can't ever be printed(?). Surely that must make sense to someone. [ while on this subject of sort, please do *not* try ] [ to sort old ps on 'args'. or better yet, if you do ] [ try that sort, see if you can determine his order, ] [ without peeking at the source. that one hurts yet! ] . All logic dealing with the old openproc flags and ps struct members known as 'need' have been whacked since that entire area was solely the new library's concern. . Remaining malloc/calloc calls to stdlib were changed to xmalloc/xcalloc from our own include/xalloc.h file. None of the replaced calls ever checked return values. [ be aware that 2 minor potential memory leaks exist ] [ depending on command line arguments. no attempt is ] [ made to free dynamically acquired format/sort node ] [ structures upon return; a conscious design choice. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-03 10:30:00 +05:30
procps_pids_unref(&Pids_info);
2002-02-02 04:17:29 +05:30
return 0;
}