Преглед на файлове

test mytop on MINIX

master
10195501441 преди 3 години
родител
ревизия
352fa28311
променени са 2 файла, в които са добавени 54 реда и са изтрити 6 реда
  1. +48
    -3
      yeeshell.c
  2. +6
    -3
      yeeshell.h

+ 48
- 3
yeeshell.c Целия файл

@ -9,14 +9,14 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ioc_tty.h>
//#include <sys/ioc_tty.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>
#include <curses.h>
#include <timers.h>
//#include <timers.h>
#include <limits.h>
#include <termcap.h>
#include <termios.h>
@ -45,9 +45,12 @@ unsigned int nr_procs, nr_tasks;
/* name of cpu cycle types, in the order they appear in /psinfo. */
const char *cputimenames[] = {"user", "ipc", "kernelcall"};
#define CPUTIMENAMES (sizeof(cputimenames) / sizeof(cputimenames[0]))
int blockedverbose = 0;
int order = ORDER_CPU;
int main()
{
char *cmdline = NULL, *pwd = NULL;
@ -892,4 +895,46 @@ struct tp *lookup(endpoint_t who, struct tp *tptab, int np)
abort();
return NULL;
}
}
int cmp_procs(const void *v1, const void *v2)
{
struct tp *p1 = (struct tp *)v1, *p2 = (struct tp *)v2;
int p1blocked, p2blocked;
if (order == ORDER_MEMORY)
{
if (p1->p->p_memory < p2->p->p_memory)
return 1;
if (p1->p->p_memory > p2->p->p_memory)
return -1;
return 0;
}
p1blocked = !!(p1->p->p_flags & BLOCKED);
p2blocked = !!(p2->p->p_flags & BLOCKED);
/* Primarily order by used number of cpu cycles.
*
* Exception: if in blockedverbose mode, a blocked
* process is always printed after an unblocked
* process, and used cpu cycles don't matter.
*
* In both cases, process slot number is a tie breaker.
*/
if (blockedverbose && (p1blocked || p2blocked))
{
if (!p1blocked && p2blocked)
return -1;
if (!p2blocked && p1blocked)
return 1;
}
else if (p1->ticks != p2->ticks)
{
return (p2->ticks - p1->ticks);
}
/* Process slot number is a tie breaker. */
return (int)(p1->p - p2->p);
}

+ 6
- 3
yeeshell.h Целия файл

@ -27,10 +27,12 @@
#define IS_SYSTEM 0x4
#define BLOCKED 0x8
#define CPUTIMENAMES (sizeof(cputimenames) / sizeof(cputimenames[0]))
#define CPUTIME(m, i) (m & (1L << (i)))
#define ORDER_CPU 0
#define ORDER_MEMORY 1
#define ORDER_HIGHEST ORDER_MEMORY
/* process info */
struct proc
{
@ -93,4 +95,5 @@ void print_procs(int maxlines, struct proc *proc1, struct proc *proc2, int cputi
u64_t cputicks(struct proc *p1, struct proc *p2, int timemode);
char *cputimemodename(int cputimemode);
void print_proc(struct tp *tp, u64_t total_ticks);
struct tp *lookup(endpoint_t who, struct tp *tptab, int np);
struct tp *lookup(endpoint_t who, struct tp *tptab, int np);
int cmp_procs(const void *v1, const void *v2);

Зареждане…
Отказ
Запис