readlink(); check bounds
top: add 'system' cpu time to 'kernel', 'idle' and 'user'
This commit is contained in:
parent
0c3199c3aa
commit
26a59eea43
3 changed files with 19 additions and 11 deletions
|
@ -110,7 +110,7 @@ void print_procs(int maxlines,
|
||||||
struct mproc *mproc)
|
struct mproc *mproc)
|
||||||
{
|
{
|
||||||
int p, nprocs;
|
int p, nprocs;
|
||||||
int idleticks = 0, kernelticks = 0;
|
int idleticks = 0, kernelticks = 0, systemticks = 0, userticks = 0;
|
||||||
|
|
||||||
for(p = nprocs = 0; p < PROCS; p++) {
|
for(p = nprocs = 0; p < PROCS; p++) {
|
||||||
if(proc2[p].p_rts_flags & SLOT_FREE)
|
if(proc2[p].p_rts_flags & SLOT_FREE)
|
||||||
|
@ -131,14 +131,19 @@ void print_procs(int maxlines,
|
||||||
/* Kernel task time, not counting IDLE */
|
/* Kernel task time, not counting IDLE */
|
||||||
if(proc2[p].p_nr < 0)
|
if(proc2[p].p_nr < 0)
|
||||||
kernelticks += tick_procs[nprocs].ticks;
|
kernelticks += tick_procs[nprocs].ticks;
|
||||||
|
else if(mproc[proc2[p].p_nr].mp_procgrp == 0)
|
||||||
|
systemticks += tick_procs[nprocs].ticks;
|
||||||
|
else
|
||||||
|
userticks += tick_procs[nprocs].ticks;
|
||||||
nprocs++;
|
nprocs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_ticks);
|
qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_ticks);
|
||||||
|
|
||||||
printf("CPU states: %5.2f%% user, %5.2f%% kernel, %5.2f%% idle\n\n",
|
printf("CPU states: %5.2f%% user, %5.2f%% system, %5.2f%% kernel, %5.2f%% idle\n\n",
|
||||||
100.0*(dt-idleticks-kernelticks)/dt,
|
100.0*userticks/dt,
|
||||||
100.0*(kernelticks)/dt,
|
100.0*systemticks/dt,
|
||||||
|
100.0*kernelticks/dt,
|
||||||
100.0*idleticks/dt);
|
100.0*idleticks/dt);
|
||||||
maxlines -= 2;
|
maxlines -= 2;
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,10 @@ At the top of the screen, top shows the current system load averages in
|
||||||
the last 1-minute, 5-minute and 15-minute intervals. Then, over the
|
the last 1-minute, 5-minute and 15-minute intervals. Then, over the
|
||||||
last top interval it displays: the number of alive, active, and sleeping
|
last top interval it displays: the number of alive, active, and sleeping
|
||||||
processes; memory free; and CPU usage. CPU usage is split into
|
processes; memory free; and CPU usage. CPU usage is split into
|
||||||
user, kernel and idle time. Kernel time is time spent by kernel tasks,
|
user, kernel, system and idle time. Kernel time is time spent by kernel tasks,
|
||||||
that is tasks that run in kernel mode in kernel address space. User
|
that is tasks that run in kernel mode in kernel address space. System
|
||||||
time is all other CPU time, including system processes such as servers
|
time are system user processes, such as drivers and servers. User
|
||||||
and drivers, as top can't see the difference between a user process and
|
time is all other CPU time.
|
||||||
a server or driver.
|
|
||||||
|
|
||||||
Then it displays all the alive processes sorted by CPU usage in the last
|
Then it displays all the alive processes sorted by CPU usage in the last
|
||||||
interval, with a number of fields for every process. Currently the
|
interval, with a number of fields for every process. Currently the
|
||||||
|
|
|
@ -274,6 +274,9 @@ PUBLIC int do_rdlink()
|
||||||
block_t b; /* block containing link text */
|
block_t b; /* block containing link text */
|
||||||
struct buf *bp; /* buffer containing link text */
|
struct buf *bp; /* buffer containing link text */
|
||||||
register struct inode *rip; /* target inode */
|
register struct inode *rip; /* target inode */
|
||||||
|
int copylen;
|
||||||
|
copylen = m_in.m1_i2;
|
||||||
|
if(copylen < 0) return EINVAL;
|
||||||
|
|
||||||
if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
|
if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code);
|
||||||
if ((rip = parse_path(user_path, (char *) 0, EAT_PATH_OPAQUE)) == NIL_INODE)
|
if ((rip = parse_path(user_path, (char *) 0, EAT_PATH_OPAQUE)) == NIL_INODE)
|
||||||
|
@ -284,11 +287,12 @@ PUBLIC int do_rdlink()
|
||||||
if (m_in.name2_length <= 0) r = EINVAL;
|
if (m_in.name2_length <= 0) r = EINVAL;
|
||||||
else if (m_in.name2_length < rip->i_size) r = ERANGE;
|
else if (m_in.name2_length < rip->i_size) r = ERANGE;
|
||||||
else {
|
else {
|
||||||
|
if(rip->i_size < copylen) copylen = rip->i_size;
|
||||||
bp = get_block(rip->i_dev, b, NORMAL);
|
bp = get_block(rip->i_dev, b, NORMAL);
|
||||||
r = sys_vircopy(SELF, D, (vir_bytes) bp->b_data,
|
r = sys_vircopy(SELF, D, (vir_bytes) bp->b_data,
|
||||||
who_e, D, (vir_bytes) m_in.name2, (vir_bytes) rip->i_size);
|
who_e, D, (vir_bytes) m_in.name2, (vir_bytes) copylen);
|
||||||
|
|
||||||
if (r == OK) r = rip->i_size;
|
if (r == OK) r = copylen;
|
||||||
put_block(bp, DIRECTORY_BLOCK);
|
put_block(bp, DIRECTORY_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue