machine.c (e2c0e292e8a7ca00ba99bcfccc9e637f45c3e8b1) | machine.c (a00d703f2f438b199d3933d19d535540586b7792) |
---|---|
1/* 2 * top - a top users display for Unix 3 * 4 * DESCRIPTION: 5 * Originally written for BSD4.4 system by Christos Zoulas. 6 * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider 7 * Order support hacked in from top-3.5beta6/machine/m_aix41.c 8 * by Monte Mitzelfelt (for latest top see http://www.groupsys.com/topinfo/) --- 210 unchanged lines hidden (view full) --- 219static int compare_jid(const void *a, const void *b); 220static int compare_pid(const void *a, const void *b); 221static int compare_tid(const void *a, const void *b); 222static const char *format_nice(const struct kinfo_proc *pp); 223static void getsysctl(const char *name, void *ptr, size_t len); 224static int swapmode(int *retavail, int *retfree); 225static void update_layout(void); 226static int find_uid(uid_t needle, int *haystack); | 1/* 2 * top - a top users display for Unix 3 * 4 * DESCRIPTION: 5 * Originally written for BSD4.4 system by Christos Zoulas. 6 * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider 7 * Order support hacked in from top-3.5beta6/machine/m_aix41.c 8 * by Monte Mitzelfelt (for latest top see http://www.groupsys.com/topinfo/) --- 210 unchanged lines hidden (view full) --- 219static int compare_jid(const void *a, const void *b); 220static int compare_pid(const void *a, const void *b); 221static int compare_tid(const void *a, const void *b); 222static const char *format_nice(const struct kinfo_proc *pp); 223static void getsysctl(const char *name, void *ptr, size_t len); 224static int swapmode(int *retavail, int *retfree); 225static void update_layout(void); 226static int find_uid(uid_t needle, int *haystack); |
227static int cmd_matches(struct kinfo_proc *, const char *); |
|
227 228static int 229find_uid(uid_t needle, int *haystack) 230{ 231 size_t i = 0; 232 233 for (; i < TOP_MAX_UIDS; ++i) 234 if ((uid_t)haystack[i] == needle) --- 629 unchanged lines hidden (view full) --- 864 865 if (sel->uid[0] != -1 && !find_uid(pp->ki_ruid, sel->uid)) 866 /* skip proc. that don't belong to the selected UID */ 867 continue; 868 869 if (sel->pid != -1 && pp->ki_pid != sel->pid) 870 continue; 871 | 228 229static int 230find_uid(uid_t needle, int *haystack) 231{ 232 size_t i = 0; 233 234 for (; i < TOP_MAX_UIDS; ++i) 235 if ((uid_t)haystack[i] == needle) --- 629 unchanged lines hidden (view full) --- 865 866 if (sel->uid[0] != -1 && !find_uid(pp->ki_ruid, sel->uid)) 867 /* skip proc. that don't belong to the selected UID */ 868 continue; 869 870 if (sel->pid != -1 && pp->ki_pid != sel->pid) 871 continue; 872 |
873 if (!cmd_matches(pp, sel->command)) 874 /* skip proc. that doesn't match grep string */ 875 continue; 876 |
|
872 *prefp++ = pp; 873 active_procs++; 874 } 875 876 /* if requested, sort the "interesting" processes */ 877 if (compare != NULL) 878 qsort(pref, active_procs, sizeof(*pref), compare); 879 880 /* remember active and total counts */ 881 si->p_total = total_procs; 882 si->p_pactive = pref_len = active_procs; 883 884 /* pass back a handle */ 885 handle.next_proc = pref; 886 handle.remaining = active_procs; 887 return (&handle); 888} 889 | 877 *prefp++ = pp; 878 active_procs++; 879 } 880 881 /* if requested, sort the "interesting" processes */ 882 if (compare != NULL) 883 qsort(pref, active_procs, sizeof(*pref), compare); 884 885 /* remember active and total counts */ 886 si->p_total = total_procs; 887 si->p_pactive = pref_len = active_procs; 888 889 /* pass back a handle */ 890 handle.next_proc = pref; 891 handle.remaining = active_procs; 892 return (&handle); 893} 894 |
895static int 896cmd_matches(struct kinfo_proc *proc, const char *term) 897{ 898 extern int show_args; 899 char **args = NULL; 900 901 if (!term) { 902 /* No command filter set */ 903 return 1; 904 } else { 905 /* Filter set, does process name contain term? */ 906 if (strstr(proc->ki_comm, term)) 907 return 1; 908 /* Search arguments only if arguments are displayed */ 909 if (show_args) { 910 args = kvm_getargv(kd, proc, 1024); 911 if (args == NULL) { 912 /* Failed to get arguments so can't search them */ 913 return 0; 914 } 915 while (*args != NULL) { 916 if (strstr(*args, term)) 917 return 1; 918 args++; 919 } 920 } 921 } 922 return 0; 923} 924 |
|
890char * 891format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags) 892{ 893 struct kinfo_proc *pp; 894 const struct kinfo_proc *oldp; 895 long cputime; 896 char status[22]; 897 size_t state; --- 677 unchanged lines hidden --- | 925char * 926format_next_process(struct handle * xhandle, char *(*get_userid)(int), int flags) 927{ 928 struct kinfo_proc *pp; 929 const struct kinfo_proc *oldp; 930 long cputime; 931 char status[22]; 932 size_t state; --- 677 unchanged lines hidden --- |