/* top.c - Source file: show Linux processes */
/*
* Copyright (c) 2002, by: James C. Warner
* All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA
* <warnerjc@worldnet.att.net>
*
* This file may be used subject to the terms and conditions of the
* GNU Library General Public License Version 2, or any later version
* at your option, as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* For their contributions to this program, the author wishes to thank:
* Albert D. Cahalan, <albert@users.sf.net>
* Craig Small, <csmall@small.dropbear.id.au>
*
* Changes by Albert Cahalan, 2002-2004.
*/
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <curses.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Foul POS defines all sorts of stuff...
#include <term.h>
#undef tab
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <values.h>
#include "proc/devname.h"
#include "proc/wchan.h"
#include "proc/procps.h"
#include "proc/readproc.h"
#include "proc/escape.h"
#include "proc/sig.h"
#include "proc/sysinfo.h"
#include "proc/version.h"
#include "proc/whattime.h"
#include "top.h"
/*###### Miscellaneous global stuff ####################################*/
/* The original and new terminal attributes */
static struct termios Savedtty,
Rawtty;
static int Ttychanged = 0;
/* Program name used in error messages and local 'rc' file name */
static char *Myname;
/* Name of user config file (dynamically constructed) and our
'Current' rcfile contents, initialized with defaults but may be
overridden with the local rcfile (old or new-style) values */
static char Rc_name [OURPATHSZ];
static RCF_t Rc = DEF_RCFILE;
/* The run-time acquired page size */
static unsigned Page_size;
static unsigned page_to_kb_shift;
/* SMP Irix/Solaris mode */
static int Cpu_tot;
static double pcpu_max_value; // usually 99.9, for %CPU display
/* assume no IO-wait stats, overridden if linux 2.5.41 */
static const char *States_fmts = STATES_line2x4;
/* Specific process id monitoring support */
static pid_t Monpids [MONPIDMAX] = { 0 };
static int Monpidsidx = 0;
/* A postponed error message */
static char Msg_delayed [SMLBUFSIZ];
static int Msg_awaiting = 0;
// This is the select() timeout. Clear it in sig handlers to avoid a race.
// (signal happens just as we are about to select() and thus does not
// break us out of the select(), causing us to delay until timeout)
static volatile struct timeval tv;
#define ZAP_TIMEOUT do{tv.tv_usec=0; tv.tv_sec=0;}while(0);
/* Configurable Display support ##################################*/
/* Current screen dimensions.
note: the number of processes displayed is tracked on a per window
basis (see the WIN_t). Max_lines is the total number of
screen rows after deducting summary information overhead. */
/* Current terminal screen size. */
static int Screen_cols, Screen_rows, Max_lines;
// set to 1 if writing to the last column would be troublesome
// (we don't distinguish the lowermost row from the other rows)
static int avoid_last_column;
/* This is really the number of lines needed to display the summary
information (0 - nn), but is used as the relative row where we
stick the cursor between frames. */
static int Msg_row;
/* Global/Non-windows mode stuff that is NOT persistent */
static int No_ksyms = -1, // set to '0' if ksym avail, '1' otherwise
PSDBopen = 0, // set to '1' if psdb opened (now postponed)
Batch = 0, // batch mode, collect no input, dumb output
Loops = -1, // number of iterations, -1 loops forever
Secure_mode = 0; // set if some functionality restricted
/* Some cap's stuff to reduce runtime calls --
to accomodate 'Batch' mode, they begin life as empty strings */
static char Cap_clr_eol [CAPBUFSIZ],
Cap_clr_eos [CAPBUFSIZ],
Cap_clr_scr [CAPBUFSIZ],
Cap_rmam [CAPBUFSIZ],
Cap_smam [CAPBUFSIZ],
Cap_curs_norm [CAPBUFSIZ],
Cap_curs_huge [CAPBUFSIZ],
Cap_home [CAPBUFSIZ],
Cap_norm [CAPBUFSIZ],
Cap_reverse [CAPBUFSIZ],
Caps_off [CAPBUFSIZ];
static int Cap_can_goto = 0;
/* Some optimization stuff, to reduce output demands...
The Pseudo_ guys are managed by wins_resize and frame_make. They
are exploited in a macro and represent 90% of our optimization.
The Stdout_buf is transparent to our code and regardless of whose
buffer is used, stdout is flushed at frame end or if interactive. */
static char *Pseudo_scrn;
static int Pseudo_row, Pseudo_cols, Pseudo_size;
#ifndef STDOUT_IOLBF
// less than stdout's normal buffer but with luck mostly '\n' anyway
static char Stdout_buf[2048];
#endif
/* ////////////////////////////////////////////////////////////// */
/* Special Section: multiple windows/field groups ---------------*/
/* The pointers to our four WIN_t's, and which of those is considered
the 'current' window (ie. which window is associated with any summ
info displayed and to which window commands are directed) */
static WIN_t Winstk [GROUPSMAX],
*Curwin;
/* Frame oriented stuff that can't remain local to any 1 function
and/or that would be too cumbersome managed as parms,
and/or that are simply more efficiently handled as globals
(first 2 persist beyond a single frame, changed infrequently) */
static int Frames_libflags; // PROC_FILLxxx flags (0 = need new)
//atic int Frames_maxcmdln; // the largest from the 4 windows
static unsigned Frame_maxtask; // last known number of active tasks
// ie. current 'size' of proc table
static unsigned Frame_running, // state categories for this frame
Frame_sleepin,
Frame_stopped,
Frame_zombied;
static float Frame_tscale; // so we can '*' vs. '/' WHEN 'pcpu'
static int Frame_srtflg, // the subject window's sort direction
Frame_ctimes, // the subject window's ctimes flag
Frame_cmdlin; // the subject window's cmdlin flag
/* ////////////////////////////////////////////////////////////// */
/*###### Sort callbacks ################################################*/
/*
* These happen to be coded in the same order as the enum 'pflag'
* values. Note that 2 of these routines serve double duty --
* 2 columns each.
*/
SCB_NUMx(P_PID, XXXID)
SCB_NUMx(P_PPD, ppid)
SCB_STRx(P_URR, ruser)
SCB_NUMx(P_UID, euid)
SCB_STRx(P_URE, euser)
SCB_STRx(P_GRP, egroup)
SCB_NUMx(P_TTY, tty)
SCB_NUMx(P_PRI, priority)
SCB_NUMx(P_NCE, nice)
SCB_NUMx(P_CPN, processor)
SCB_NUM1(P_CPU, pcpu)
// also serves P_TM2 !
static int sort_P_TME (const proc_t **P, const proc_t **Q)
{
if (Frame_ctimes) {
if ( ((*P)->cutime + (*P)->cstime + (*P)->utime + (*P)->stime)
< ((*Q)->cutime + (*Q)->cstime + (*Q)->utime + (*Q)->sti
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于Linux C 接口封装的一些接口. 便于在实际Linux C应用开发中使用..zip (421个子文件)
00list 850B
top.1 63KB
ps.1 41KB
pgrep.1 4KB
skill.1 3KB
kill.1 3KB
slabtop.1 3KB
w.de.1 2KB
watch.1 2KB
w.1 2KB
free.1 2KB
tload.1 1KB
pmap.1 1003B
uptime.1 902B
pwdx.1 890B
pkill.1 17B
snice.1 17B
sysctl.conf.5 1KB
vmstat.8 5KB
sysctl.8 2KB
10-zeropage.conf.armel 532B
10-zeropage.conf.armhf 532B
AUTHORS 1KB
benchmark 42B
procps.bug-presubj 245B
BUGS 3KB
top.c 110KB
output.c 80KB
parser.c 39KB
sysinfo.c 32KB
readproc.c 31KB
sortformat.c 28KB
ustring.c 28KB
parsec.c 22KB
vmstat.c 21KB
minimal.c 19KB
ksym.c 17KB
display.c 17KB
pgrep.c 17KB
skill.c 16KB
uslog.c 15KB
test_ustrcpy.c 15KB
global.c 14KB
sysctl.c 13KB
test_ustrsplit.c 13KB
ulogshms.c 12KB
test_ustrtrim.c 12KB
devname.c 12KB
umd5.c 12KB
ufile.c 11KB
umalloc.c 11KB
test_ump_simple.c 10KB
md5.c 10KB
ucycm.c 10KB
pmap.c 10KB
ulogconf.c 9KB
ubitbuffer.c 9KB
socket.c 9KB
slab.c 9KB
w.c 9KB
slabtop.c 9KB
uconf-parse.c 8KB
watch.c 7KB
ucycm_read.c 7KB
ulinklist.c 7KB
uthreads.c 7KB
ulogpro.c 7KB
ubuffer.c 6KB
sig.c 6KB
ump_simple.c 6KB
escape.c 6KB
test_ubuffer_split.c 5KB
usvmesgs.c 5KB
ustrset.c 5KB
utv.c 5KB
select.c 5KB
uarray.c 5KB
test_ubuffer_rw_api.c 5KB
test_ump_simple_running.c 5KB
ubuffer_rw.c 4KB
ubacktrace.c 4KB
free.c 4KB
smaps.c 4KB
main.c 4KB
crc.c 4KB
test_ucycm_read_newest_running.c 3KB
ucrc.c 3KB
test_ulinklist.c 3KB
uqueue.c 3KB
tload.c 3KB
ubuffer_format.c 3KB
usocket.c 3KB
usvmesgc.c 3KB
ubuffer_format.c 3KB
pwdx.c 2KB
ukeyword.c 2KB
help.c 2KB
whattime.c 2KB
test_umemmove.c 2KB
test_ubitget.c 2KB
共 421 条
- 1
- 2
- 3
- 4
- 5
资源评论
博士僧小星
- 粉丝: 2263
- 资源: 5991
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2024 年 Java 开发人员路线图.zip
- matplotlib-3.7.5-cp38-cp38-win-amd64.whl
- Android TV 开发框架: 包含 移动的边框,键盘,标题栏
- 图像处理中白平衡算法之一的灰度世界算法的MATLAB实现
- Cython-3.0.10-cp38-cp38-win-amd64.whl
- zotero安卓版"Zotero Beta"版本1.0.0-118
- Web应用项目开发的三层架构
- 基于QT和OpenCV的Mask编辑工具(python源码)
- 418.基于SpringBoot的个性化电影推荐系统.zip
- 417.基于SpringBoot的高校学生饮食推荐系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功