From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: dominik.vogt@gmx.de, zsh-users@sunsite.auc.dk
Subject: Re: displaying top cpu using process
Date: Sat, 7 Apr 2001 18:26:01 +0000 [thread overview]
Message-ID: <1010407182602.ZM15804@candle.brasslantern.com> (raw)
In-Reply-To: <20010407163348.A619@gmx.de>
On Apr 7, 4:33pm, Dominik Vogt wrote:
} Subject: displaying top cpu using process
}
} ps gives me complete control over the output format, but I can't
} make it give me the CPU percentage. Although the 'C' output
} modifier is documented as
}
} "use raw CPU time for %CPU instead of decaying average"
}
} I always get the decaying average.
I can't even get my "ps" to accept the C modifier. It keeps interpreting
it as the "selection by command name" option, and telling me that only
root is allowed to do that.
} top -b -n 1 | sed '<script>'
}
} But then, this only works if the terminal window from which top
} was started has enough lines. [...] To get the full output I
} have to detach top from the terminal.
That's odd; on RH6.2, for me, "top -b -n 1" produces a lot more lines
of output than the height of the terminal. (procps-2.0.6-5) However,
try fooling it by stuffing the LINES and COLUMNS environment variables.
} In other words, I need one process that generates the data and one
} that writes it into the terminal window. There are several ways to
} do this, but the best solution seems to be a coprocess (because the
} coprocess is killed if the terminal window that runs the script is
} closed).
A coprocess is overkill. Just use the parameter assignment and a pipe:
topcpu {
local p=0 pid user pri ni size rss share stat lib cpu mem time command
LINES=10 COLUMNS=200 top d 2 c b n 43200 |
while read pid user pri ni size rss share stat lib cpu mem time command
do
[[ $pid == PID ]] && { p=1; continue }
(( p )) && { print $pid $cpu% $command; p=0 }
done
}
43200 iterations of 2 sec is 24 hours.
} Can anybody think of a better solution (that does not include
} writing any C code)?
Presumably it's possible to compute the CPU percentages by reading from
/proc/<->/stat plus the cpu line from /proc/stat, but I don't know the
algorithm top uses.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
next prev parent reply other threads:[~2001-04-07 18:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-07 14:33 Dominik Vogt
2001-04-07 18:26 ` Bart Schaefer [this message]
2001-04-08 12:49 ` Dominik Vogt
2001-04-08 17:04 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1010407182602.ZM15804@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=dominik.vogt@gmx.de \
--cc=zsh-users@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).